expo prebuild command generates native ios/ and android/ directories from your app configuration, enabling you to use native code, libraries, and build tools directly.
Usage
Arguments
Directory of the Expo project. Defaults to the current working directory.
Options
Platforms to generate:
ios, android, or all. Default: all. Alias: -pDelete the native folders and regenerate them before applying changes. Ensures a fresh state.
Skip installing npm packages and CocoaPods.
Package Manager Options
Use npm to install dependencies. Default when
package-lock.json exists.Use Yarn to install dependencies. Default when
yarn.lock exists.Use pnpm to install dependencies. Default when
pnpm-lock.yaml exists.Use bun to install dependencies. Default when
bun.lock or bun.lockb exists.Project template to clone from. Can be:
- File path to a local tar file
- npm package name
- GitHub repository URL
Comma-separated list of packages to preserve versions in package.json. Useful for testing specific versions.
What is Prebuild?
Prebuilding is the process of generating native iOS and Android projects from your Expo app configuration. This is necessary when you need to:- Use native modules that require custom native code
- Modify native build configuration
- Add native dependencies not available in Expo Go
- Prepare for building with Xcode or Android Studio
- Use EAS Build or build locally with
expo run
When to Use Prebuild
You Need Prebuild When:
- Installing a library that requires native code changes
- Adding custom native modules
- Modifying native build settings
- Setting up custom URL schemes or app extensions
- Configuring native permissions or capabilities
- Building for production
You Don’t Need Prebuild When:
- Working with Expo Go
- All your dependencies are supported by Expo Go
- Doing JavaScript-only development
- Using managed workflow exclusively
Examples
Basic Prebuild
Generate both iOS and Android projects:ios/directory with Xcode projectandroid/directory with Gradle project- Installs native dependencies (CocoaPods for iOS)
Generate Specific Platform
iOS only:Clean Prebuild
Delete existing native folders and regenerate:- You’ve made manual changes you want to discard
- You want to ensure configuration is correctly applied
- You’re troubleshooting build issues
Skip Installation
Generate native projects without installing dependencies:Specify Package Manager
Use a specific package manager:Custom Template
Use a custom template:Preserve Package Versions
Keep specific package versions during prebuild:How It Works
When you runexpo prebuild, the CLI:
- Reads Configuration - Loads app.json or app.config.js
- Validates Dependencies - Checks for native module compatibility
- Generates Native Projects - Creates ios/ and android/ directories
- Applies Config Plugins - Runs config plugins to modify native files
- Installs Dependencies - Runs
pod installfor iOS - Syncs Configuration - Applies settings from app config to native projects
Generated Files
iOS Directory Structure
Android Directory Structure
Config Plugins
Prebuild uses Config Plugins to modify native projects. These plugins run during prebuild to configure native code based on your app.json.Common Config Plugins
- expo-camera - Adds camera permissions
- expo-location - Configures location services
- expo-notifications - Sets up push notifications
- expo-splash-screen - Generates splash screens
- expo-updates - Configures OTA updates
Example Configuration
app.json
Continuous Prebuilding
You can safely runexpo prebuild multiple times. The command is idempotent, meaning:
- Running it again with the same config produces the same result
- Changes in app.json are applied to native projects
- Manual native changes are preserved if not in conflict
Best Practice
Use--clean flag when you want to ensure a pristine state:
Manual Native Changes
After prebuilding, you can make manual changes to native code:- Open
ios/*.xcworkspacein Xcode - Open
android/in Android Studio - Modify native code, add files, configure settings
Important Notes
- Manual changes may be overwritten by future prebuilds
- Use Config Plugins for reproducible native configuration
- Version control your native directories to track changes
- Document manual changes for team members
Gitignore Native Directories
You can choose to either commit or ignore native directories:Option 1: Ignore Native Directories (Recommended for Teams)
Add to.gitignore:
- Smaller repository size
- No merge conflicts in native files
- Easy to regenerate with
expo prebuild - Enforces declarative configuration
Option 2: Commit Native Directories
Benefits:- Full control over native code
- Can make manual native changes
- Easier to see what changed
- No need to rebuild for reviewers
Troubleshooting
CocoaPods Installation Fails (iOS)
Update CocoaPods:Gradle Build Fails (Android)
Check Java version:Config Plugin Errors
Ensure all packages with config plugins are installed:Prebuild Keeps Failing
Try a clean prebuild:Platform Not Supported
iOS prebuild is not supported on Windows. Use:- macOS for iOS development
- EAS Build for cloud building
--platform androidflag to skip iOS
Comparing Workflows
| Workflow | Native Directories | Expo Go | Custom Native Code |
|---|---|---|---|
| Managed | Not generated | ✓ | ✗ |
| Prebuild | Generated | ✗ | ✓ |
| Bare | Committed | ✗ | ✓ |