Reputation: 607
I want to link only one of my project (Android or iOS) with the npm package. Is there any way to do it?
Upvotes: 18
Views: 19516
Reputation: 1543
if react-native < 60
react-native link your-library-js-package-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:
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
Upvotes: 14
Reputation: 316
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
Upvotes: 30
Reputation: 734
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.
Upvotes: 2