ios/ and android/ directories from your app.json configuration and installed packages. It’s like a bundler for native code.
What is Prebuild?
Prebuild transforms your Expo project configuration into native iOS and Android projects:Why Use Prebuild?
Advantages
- Reproducible: Same
app.json= same native projects - Version control: Can ignore
ios/andandroid/in git - Easy updates: Regenerate when config changes
- Config plugins: Modify native code declaratively
- Clean slate: Reset native projects anytime
When to Use
- Development builds: Generate native code for custom modules
- CI/CD: Reproducible native projects in CI
- Config changes: When updating
app.jsonplugins - Clean start: Reset corrupted native projects
Running Prebuild
Basic Usage
Options
Prebuild Process
Clean vs Modified Projects
Clean Projects
Native projects that can be regenerated from config:- Always in sync with config
- No merge conflicts in native code
- Easy to update SDK versions
- Must run prebuild before building
- Can’t make manual native changes
- Requires CI to run prebuild
Modified Projects
Projects with manual native modifications:- Can make any native changes
- No prebuild step needed
- Direct control over native code
- Hard to keep in sync with config
- Merge conflicts in native code
- Manual SDK updates
Config Plugins
Plugins modify native projects declaratively.Using Plugins
app.json
Creating Custom Plugins
plugins/withCustomConfig.js
Plugin Examples
Modify iOS Entitlements
Add Android Permissions
Modify Gradle
Templates
Prebuild uses templates to generate native projects.Default Template
Custom Template
Template Structure
template.config.js
Workflow Strategies
Strategy 1: Clean Projects (Recommended)
Workflow:- Standard Expo modules only
- No custom native code
- Team prefers simplicity
- CI/CD builds
Strategy 2: Modified Projects
Workflow:- Custom native code
- Third-party SDKs
- Advanced configurations
- Need full native control
Strategy 3: Hybrid
Workflow:CI/CD Integration
GitHub Actions
.github/workflows/build.yml
EAS Build
EAS Build runs prebuild automatically:eas.json
Troubleshooting
Prebuild Fails: Package Conflicts
Native Directories Out of Sync
CocoaPods Install Fails
Gradle Sync Fails
Plugin Errors
Best Practices
1. Use Clean Projects When Possible
2. Document Custom Changes
If modifying native code:NATIVE_CHANGES.md
3. Test After Prebuild
4. Keep Config Plugins Simple
5. Version Lock Templates
app.json
Next Steps
Build Properties
Configure native build settings
Creating Builds
Build your prebuilt project
Native Modules
Create custom native modules
Monorepos
Use prebuild in monorepos