You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

非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 -v in your terminal to verify your version. If it’s outside the recommended range, use a version manager like nvm to switch:
    nvm install 20
    nvm use 20
    
  • Android SDK Path Issues: Make sure your ANDROID_HOME environment variable is set correctly.
    • On macOS/Linux, add these lines to your ~/.bashrc or ~/.zshrc file:
      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_HOME via System Properties > Environment Variables, pointing to your Android SDK folder (usually C:\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.
  • Gradle Corruption: Gradle wrapper files can sometimes get corrupted. Fix this by:
    1. Deleting the android/.gradle folder in your project
    2. Running cd android && ./gradlew clean (macOS/Linux) or cd android && gradlew clean (Windows)
    3. Returning to your project root and running npx react-native run-android again
  • Missing Dependencies: If your project setup was interrupted, you might be missing core packages. Run npm install or yarn install in 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 devices to 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-server followed by adb 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 07:42:42