React Native应用运行卡顿求助:执行react-native run-android后应用卡住
react-native run-android Hey there! Sorry to hear your React Native Android app is freezing up right after running react-native run-android—let’s go through some tried-and-true fixes that typically resolve this kind of issue.
Common Troubleshooting Steps
1. Restart the Metro Bundler (with Cache Reset)
More often than not, the Metro server gets stuck in a bad state or holds onto stale cached data. Here’s how to reset it:
- Close any open Metro terminal processes completely.
- Open a new terminal in your project root, run:
react-native start --reset-cache - Once Metro is up and running smoothly, open another terminal and re-run:
react-native run-android
The --reset-cache flag is critical here—it clears out old JavaScript and asset caches that frequently cause startup hangs.
2. Check Your Android Device/Emulator
If the app is getting stuck on the device side, try these quick checks:
- Emulator users: Restart your emulator (sometimes it’s just starved for resources). You can also head to the AVD Manager and increase the emulator’s allocated RAM/CPU—too little memory will make apps freeze on launch.
- Physical device users: Double-check that USB debugging is enabled on your device, then run
adb devicesto confirm your computer detects it. If not, re-plug the USB cable or toggle USB debugging off and on again.
3. Clean Project Builds & Caches
Corrupted build files are another common culprit:
- Navigate to your project’s Android directory and clean the Gradle build:
cd android && ./gradlew clean - Go back to the root directory and clear your package manager cache:
# For npm users npm cache clean --force # For yarn users yarn cache clean - Now rebuild the app with
react-native run-android.
4. Verify Dependency Version Compatibility
Mismatched versions of React Native, Android Gradle Plugin (AGP), or Gradle itself can lead to silent startup failures:
- Check the official React Native documentation for your RN version to confirm the recommended AGP and Gradle versions.
- Update
android/build.gradle(for AGP) andandroid/gradle/wrapper/gradle-wrapper.properties(for Gradle) to match the recommended versions, then re-run the build.
5. Dig Into Debug Logs
If none of the above works, we need to pinpoint the exact error:
- Run the build with verbose logging to see detailed output:
react-native run-android --verbose - Or open your project’s
androidfolder in Android Studio, go to the Logcat tab, and filter for your app’s package name. Look for red-marked error messages that pop up when the app gets stuck—this will lead you to the root cause (e.g., missing permissions, faulty native modules, etc.).
If you try all these steps and still have issues, share the relevant log snippets, and we can narrow it down further!
内容的提问来源于stack exchange,提问作者EDISON J

