In this lesson, you will learn how to safely link and integrate third-party native modules into your React Native project without breaking your existing build pipeline.
When you use a library that requires "native code"—meaning it talks directly to iOS or Android hardware—you aren't just downloading JavaScript files. You are importing native project files that must be compiled alongside your app.
The Modern Linking Process
In earlier versions of React Native, you had to manually edit files like AppDelegate.mm or build.gradle to link libraries. Today, React Native’s Autolinking feature handles this for you. When you install a package using npm or yarn, the CLI automatically detects the native components and links them during the build process.
To integrate a library safely, follow these three steps:
- Install the package: Run your standard install command (e.g.,
npm install react-native-some-library). - Run the Native Pods (iOS only): Because iOS manages native dependencies via CocoaPods, you must navigate to your
iosfolder and runpod installto update your project’s native workspace. - Rebuild the Native Binary: Since these libraries modify your app’s native layer, you cannot simply refresh the app using Fast Refresh. You must stop your Metro bundler and run
npx react-native run-iosornpx react-native run-androidto compile the new native code into your app binary.
Example: Integrating a Native Module
If you were adding a native library like react-native-device-info, your workflow looks like this:
# 1. Install the dependency
npm install react-native-device-info
# 2. Update iOS native project
cd ios && pod install && cd ..
# 3. Rebuild the app (Crucial!)
npx react-native run-ios
Always check the library’s README for any extra "Post-install" steps, such as adding permissions to your Info.plist or AndroidManifest.xml. If you skip the native rebuild, your JavaScript will try to call a native method that doesn't exist yet, resulting in a "Native module cannot be null" error.
Key Takeaway: Third-party native modules require a fresh compilation of your project's binary, so always re-run your build command after adding or updating native dependencies.