Understanding Continuous Native Generation (CNG) in React Native: Expo Go vs. CNG Workflows
React Native development has evolved significantly with tools like Expo, which simplify building cross-platform apps. Two key workflows dominate the ecosystem: Expo Go (for rapid prototyping) and Continuous Native Generation (CNG) (for advanced customization). This post explores their differences, use cases, and how to leverage them effectively.
What is Continuous Native Generation (CNG)?
CNG is an Expo workflow that generates native iOS/Android projects on-demand using declarative configurations (like app.json
and config plugins). Instead of manually maintaining ios
and android
directories, CNG creates them dynamically during builds, enabling seamless upgrades and dependency management.
Key Features of CNG:
- On-Demand Native Code: Generated via
expo prebuild
orexpo run:android/ios
. - Config Plugins: Modify native projects programmatically (e.g., adding entitlements, dependencies).
- No Manual Maintenance: Native directories are treated as build artifacts, reducing upgrade friction.
Expo Go: The Quickstart Workflow
Expo Go is a prebuilt app for testing React Native projects instantly via QR code. It’s ideal for:
- Prototyping without native code.
- Sharing demos with stakeholders.
Limitations:
- No Custom Native Code: Apps using native modules (e.g.,
react-native-mmkv
) crash in Expo Go. - Restricted APIs: Limited to Expo SDK features (e.g., camera, notifications).
CNG vs. Expo Go: A Side-by-Side Comparison
Feature |
Expo Go |
CNG |
Native Code Support |
❌ Only Expo SDK modules |
✅ Custom native code & libraries |
Workflow |
expo start + QR code scan |
expo run:android/ios + local builds |
Project Structure |
No ios/android directories |
Generates ios/android dynamically |
Upgrades |
Automatic via Expo SDK updates |
Managed via expo prebuild --clean |
Use Case |
Prototyping, simple apps |
Production apps with native features |
Workflow Examples
1. Switching from Expo Go to CNG
To add native functionality (e.g., react-native-mmkv
):
- Update
package.json
Scripts:
"android": "expo run:android",
"ios": "expo run:ios" - Remove Native Directories:
rm -rf android ios
- Run CNG:
npx expo prebuild --clean
# Generates fresh native projects
npm run android # Builds and launches the app
2. Adding a Home Screen Widget with CNG
Using CNG’s config plugins, you can generate native iOS targets for widgets:
{
"plugins": [
["@bacons/widgets", { "targetName": "MyWidget" }]
]
}
When to Use Each Workflow
- Expo Go:
- Early-stage prototyping.
- Apps without custom native code.
- Teams needing rapid iteration.
- CNG:
- Apps requiring native modules (e.g., Bluetooth, custom SDKs).
- Projects needing platform-specific configurations (e.g., App Groups for widgets) 10.
- Long-term maintainability with automated native code generation.
Conclusion
Expo Go and CNG cater to different stages of app development. While Expo Go accelerates initial prototyping, CNG empowers developers to scale apps with native features without sacrificing Expo’s tooling. By understanding their strengths, teams can choose the right workflow for their project’s lifecycle.
Further Reading:
Visual Appendix
Diagram: Expo Go vs. CNG Workflow
Expo Go Workflow:
[JS Code] → Expo Go App → Instant Preview
CNG Workflow:
[JS Code + Config Plugins] → expo prebuild → [Native Projects] → Local/EAS Build → Production App
Command Cheat Sheet
Task |
Expo Go Command |
CNG Command |
Start Dev Server |
expo start |
expo start |
Build Android |
N/A (QR code only) |
expo run:android |
Regenerate Native Code |
N/A |
expo prebuild --clean |
Add Config Plugin |
N/A |
npx expo install expo-camera |