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

执行react-native run-android命令报错500:安卓设备/模拟器中命令终止

Hey there, let's break down why you're hitting that 500 error when running react-native run-android on both physical Android devices and emulators. This is a super common gotcha, so don't stress—here are the most likely culprits and fixes:

Common Causes & Fixes for React Native Android 500 Server Error
  • 1. Metro Server Isn't Running (or Crashed Silently)
    Sometimes the Metro bundler fails to spin up automatically, or crashes in the background without you noticing. Try this:

    • Kill any existing Metro processes (close the terminal tab it's running in, or use killall node on macOS/Linux, taskkill /F /IM node.exe on Windows).
    • Manually start Metro with npx react-native start --reset-cache—the --reset-cache flag is key here, since stale cached files are a frequent cause of this error.
    • Once Metro is up and running smoothly, open a fresh terminal and run react-native run-android again.
  • 2. Port Conflicts
    Metro uses port 8081 by default, and if another app is hogging that port, the server throws a 500 error.

    • Check if port 8081 is occupied: run lsof -i :8081 (macOS/Linux) or netstat -ano | findstr :8081 (Windows). If you see a process using it, terminate it.
    • Alternatively, run Metro on a different port with npx react-native start --port 8082, then match it with react-native run-android --port 8082.
  • 3. Network Mismatch Between Device/Emulator and Dev Machine
    Both physical devices and emulators need to reach your Metro server, which requires proper network setup.

    • For physical devices: Ensure your phone is on the same Wi-Fi as your computer. If using USB debugging, run adb reverse tcp:8081 tcp:8081 to bypass network routing issues.
    • For emulators: Sometimes emulators struggle to resolve your computer's IP. Open the developer menu (shake the emulator or press Ctrl+M/Cmd+M), select "Change Bundle Location", and enter your computer's local IP plus :8081 (e.g., 192.168.1.100:8081).
  • 4. Corrupted Dependencies or Build Artifacts
    Broken node modules or stale Android build files can trigger unexpected server errors.

    • Delete the node_modules folder and reinstall dependencies: rm -rf node_modules && npm install (or yarn install if you use Yarn).
    • Clean the Android build folder: cd android && ./gradlew clean && cd .., then re-run react-native run-android.
  • 5. Outdated React Native or Dependencies
    Older versions of React Native or related packages might have bugs that cause this 500 error.

    • Verify if your React Native version is up to date (check the latest stable release notes for guidance). If not, follow the official upgrade steps tailored to your project.
    • Run npm audit to check for vulnerable dependencies and update them as needed.

If none of these fix the issue, take a close look at the full Metro server logs—sometimes the 500 error hides a more specific message (like a syntax error in your code) that's printed in the Metro terminal tab. That can give you a clearer clue about what's going wrong.

内容的提问来源于stack exchange,提问作者Kashifweb

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 15:38:00