Used to link the native components/modules to the React Native app. The native features are exposed as independent static libraries.
Automatic linking
npx react-native link
usually does the job. It goes through dependencies
/devDependencies
in package.json
and links the libraries with native dependencies automagically.
iOS
If the iOS project is using CocoaPods (contains Podfile
) and the library has podspec
file, react-native link
will add the library to Podfile.
Manual linking
iOS
- Drag the library's
.xcodeproj
file inside Libraries in Xcode. - Go to Project -> Build Phases
- Drag the static library from Libraries -> library -> Products to Link Binary With Libraries section.
- (optional) Include the path to the library in Project -> Build Settings -> Header Search Paths (non-recursive) - this is needed if you need to call the native parts of the library from the native part of the app that you're developing.
Android
- Add dependency path to
settings.gradle
:
gradle
include ':react-native-ble-manager'
project(':react-native-ble-manager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-ble-manager/android')
- Add
implementation <library_name>
toapp.build.gradle
:
gradle
dependencies {
compile project(':react-native-ble-manager')
}
- Import the native package in
MainApplication.java
:
java
import it.innove.BleManagerPackage;
public class MainApplication extends Application implements ReactApplication {
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new BleManagerPackage()
);
}
}