Overview
While Expo provides a comprehensive SDK, sometimes you need custom native code or third-party libraries with native dependencies. Expo’s prebuild workflow makes this possible while maintaining a great developer experience.Understanding Prebuild
Expo’s prebuild workflow generates theios and android directories from your app.json configuration:
ios/- Xcode projectandroid/- Android Studio project
Prebuild is similar to
eject but reversible. You can delete the native directories and regenerate them anytime.When to Use Custom Native Code
- Adding third-party libraries with native dependencies
- Implementing features not available in Expo SDK
- Integrating platform-specific SDKs (payment processors, analytics, etc.)
- Building custom native modules
- Modifying native build configuration
Adding Native Libraries
1
Install the library
2
Run prebuild
- Links the native module
- Updates CocoaPods (iOS)
- Updates Gradle dependencies (Android)
3
Rebuild the app
Example: Adding react-native-maps
app/map.tsx
Config Plugins
Config plugins modify the native projects during prebuild without manual editing:app.json
Common plugins
- Maps
- Firebase
- IAP
app.json
Creating Custom Native Modules
Using Expo Modules API
The modern way to create native modules:1
Create a local Expo module
2
Implement iOS module
modules/my-module/ios/MyModule.swift
3
Implement Android module
modules/my-module/android/src/main/java/expo/modules/mymodule/MyModule.kt
4
Use the module
app/index.tsx
Module capabilities
- Functions
- Events
- Constants
- Views
Creating Config Plugins
Config plugins automate native configuration:plugins/withCustom.js
app.json
Modifying Native Code Directly
If you need full control:1
Run prebuild without gitignore
app.json
2
Modify native files
Edit
ios/ and android/ directories directly in Xcode or Android Studio.3
Commit changes
Development Workflow
With prebuild (recommended)
With native directories
EAS Build with Custom Native Code
Custom native code works seamlessly with EAS Build:eas.json
npx expo prebuild automatically.
Troubleshooting
Native module not found after installation
Native module not found after installation
Build fails after adding native dependency
Build fails after adding native dependency
- Check minimum iOS/Android version requirements
- Verify the library is compatible with React Native version
- Look for config plugin in library documentation
- Check for peer dependency warnings
Changes to app.json not reflected
Changes to app.json not reflected
--clean flag removes and regenerates native directories.Custom module not updating
Custom module not updating
Best Practices
- Use config plugins: Automate native configuration instead of manual editing
- Stay in managed workflow: Keep native directories gitignored when possible
- Document native dependencies: List libraries with native code in README
- Test on both platforms: Native code behavior can differ
- Use Expo Modules API: Prefer it over React Native’s legacy bridge
- Version lock native dependencies: Specify exact versions to avoid breaking changes
- Clean rebuilds: Run
npx expo prebuild --cleanwhen in doubt - Check compatibility: Verify libraries work with your Expo SDK version
Migration from Bare Workflow
If you have existing native directories:1
Backup native changes
2
Remove native directories
3
Add plugins for native changes
Convert manual native modifications to config plugins in
app.json.4
Regenerate with prebuild
5
Test thoroughly