React Native带原生代码项目的判定及定义咨询
react-native init & Understand "Project with Native Code Required" Great questions—this is a super common point of confusion for React Native developers, especially when switching between different project setups. Let’s break this down step by step.
1. What does "Project with Native Code Required" actually mean?
Put simply, this refers to React Native projects that include full access to iOS and Android native codebases. These projects have dedicated ios/ and android/ directories in their root, which contain the platform-specific native code (Objective-C/Swift for iOS, Java/Kotlin for Android).
Unlike Expo Managed projects (which abstract away native code and rely entirely on the Expo SDK), these projects let you:
- Modify native files directly (e.g., tweak
AndroidManifest.xml, add iOS CocoaPods dependencies) - Use third-party native modules that require manual linking or custom native setup
- Compile and run the app directly via Xcode or Android Studio
If a feature or library labels itself "Project with Native Code Required", it means it can’t be used in Expo Managed projects without first ejecting (a process that adds the native code directories to the project).
2. How to check if a project was created with react-native init and has native code?
Here are the most reliable ways to verify:
- Look for native platform directories: The easiest tell is checking your project root for
ios/andandroid/folders.react-native initcreates these by default, so if both exist, you’re dealing with a native code project. - Inspect
package.jsonscripts: Check the"scripts"section for entries like"run-ios": "react-native run-ios"and"run-android": "react-native run-android". These are standard inreact-native initprojects, whereas Expo projects will have scripts like"start": "expo start"instead. - Check the app entry file:
react-native initprojects typically useindex.js(orindex.tsxfor TypeScript) as the main entry point. Expo Managed projects usually rely onApp.js/App.tsxas the starting file, with noios//android/folders present. - Test native run commands: Try running
react-native run-androidorreact-native run-iosin your terminal. If the command compiles the app and launches it in an emulator/simulator, it’s a native code project. If you get an error about missingandroid/orios/directories, it’s likely not.
A quick note: Some projects might have started as Expo Managed and then been ejected (using expo eject), which adds the ios/ and android/ directories. These also count as "projects with native code"—they just didn’t start with react-native init.
内容的提问来源于stack exchange,提问作者Kar

