I want to link only one of my project (Android or iOS) with the npm package. Is there any way to do it?
Asked
Active
Viewed 1.8k times
18
-
If you're using `git`, there's a simple workaround. Just link it, then checkout all the ios files that were changed `git checkout ios/*` – Fawaz Oct 26 '18 at 06:36
3 Answers
30
You can choose to link libraries for only a certain platform by doing:
For Android: react-native link (your_library_name_here) --platforms android
For iOS: react-native link (your_library_name_here) --platforms ios

Ennis Machta
- 316
- 3
- 4
14
if react-native < 60
- rename platforms ( iOS or Android) that you don't want to link.
- run
react-native link your-library-js-package-name
. - rename platforms to the original name.
.
react-native >= 60
because the new react-native versions have some auto-linking feature you should tell the react-native CLI to do not link your library:
- create a
react-native.config.js
file in the root of your project. add some config like this
module.exports = { dependencies: { 'your-library-js-package-name': { platforms: { android: null, // assign null to disable autolinking ios: // assign null to disable autolinking or remove the ios key to let do the default linking }, }, }, };
check this for more info docs

Ahmad Dehnavi
- 1,483
- 1
- 17
- 20
-
This not always work, I rename my folder to `rename_ios` and still make the linking – Juan P. Ortiz Sep 24 '19 at 16:27
-
@Juan P. Ortiz, react native 60 and later have an auto-linking feature so this solution will not work for you if you use auto-linking. – Ahmad Dehnavi Sep 25 '19 at 13:24
2
When you run react-native link, it will link to required platform automatically.
If Module/dependency is required for iOS/Android only then will link to iOS/Android only.
If for both then linking will be for both.
And you can link to a platform manually as well.

Deepak
- 724
- 4
- 13
-
1Yes, but what if I don't want that module on iOS. I can manually link it on Android, right? – Aaditya Paliwal Aug 02 '18 at 06:31
-
So that's what I want from react-native link, if it has any way to do it. – Aaditya Paliwal Aug 02 '18 at 07:16
-
-