非Expo方式启动React Native遇报错,真机按文档操作运行仍出错
Hey there! Let's tackle those frustrating React Native errors you're hitting—both when starting a non-Expo project and running on a real device. I’ve helped tons of developers work through these exact issues, so let’s break down the most common fixes step by step.
Non-Expo React Native Startup Errors
These usually boil down to environment misconfigurations or missing setup steps. Here’s what to check:
- Node.js Version Mismatch: React Native relies on specific LTS Node versions (typically 18.x or 20.x). Run
node -vin your terminal to verify your version. If it’s outside the recommended range, use a version manager likenvmto switch:nvm install 20 nvm use 20 - Android SDK Path Issues: Make sure your
ANDROID_HOMEenvironment variable is set correctly.- On macOS/Linux, add these lines to your
~/.bashrcor~/.zshrcfile:export ANDROID_HOME=$HOME/Library/Android/sdk export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=$PATH:$ANDROID_HOME/platform-tools - On Windows, set
ANDROID_HOMEvia System Properties > Environment Variables, pointing to your Android SDK folder (usuallyC:\Users\YourName\AppData\Local\Android\Sdk). Also, confirm you’ve installed all required SDK components (Android SDK Platform, SDK Build Tools, Android Support Repository) through Android Studio’s SDK Manager.
- On macOS/Linux, add these lines to your
- Gradle Corruption: Gradle wrapper files can sometimes get corrupted. Fix this by:
- Deleting the
android/.gradlefolder in your project - Running
cd android && ./gradlew clean(macOS/Linux) orcd android && gradlew clean(Windows) - Returning to your project root and running
npx react-native run-androidagain
- Deleting the
- Missing Dependencies: If your project setup was interrupted, you might be missing core packages. Run
npm installoryarn installin your project root to ensure all dependencies are properly installed.
Real Device Run Errors (Following Official Docs)
Even with the official steps, real-device issues often come down to device permissions or connection problems. Try these fixes:
- USB Debugging & Authorization:
- Enable USB Debugging on your Android device (Settings > Developer Options > USB Debugging). If you don’t see Developer Options, go to Settings > About Phone and tap "Build Number" 7 times to unlock it.
- When you connect your device to your computer, a pop-up will appear on the device asking to allow USB debugging from your computer—tap "Allow". If you miss this, revoke USB debugging authorizations (in Developer Options) and reconnect.
- ADB Connection Troubleshooting: Run
adb devicesto check if your device is listed. If not:- Unplug and re-plug the USB cable, switching the connection mode to "File Transfer (MTP)" instead of charging-only
- Restart the ADB server:
adb kill-serverfollowed byadb start-server
- iOS Real Device Checks:
- Ensure your Apple Developer account is linked in Xcode, and your device is added to your account (Xcode > Preferences > Accounts > Manage Certificates).
- On your iOS device, go to Settings > General > VPN & Device Management and trust the developer certificate associated with your app.
- If you get a "Could not find developer disk image" error, open Xcode and let it install the required components for your device’s iOS version.
- Release Build Signing: For Android release builds, confirm you’ve generated a keystore and configured it in
android/app/build.gradle. Even debug builds sometimes need a valid debug keystore—you can generate one with:keytool -genkey -v -keystore ~/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
If you’re still stuck, share the exact error messages you’re seeing—they’ll help narrow down the problem even faster!
内容的提问来源于stack exchange,提问作者SURENDRA GIRI
相关产品推荐
相关产品推荐

