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

在Windows构建React Native应用及Android模拟器打包时遇报错求助

Hey there, let's tackle those React Native build and Android emulator packaging errors you're hitting on Windows—these issues are super common, and I’ve got some tried-and-true fixes to walk you through.

First, Check Your Base Environment Setup

A lot of build failures boil down to misconfigured environment variables or incompatible tool versions. Here’s what to verify:

  • Android SDK & Environment Variables
    Make sure ANDROID_SDK_ROOT (or the older ANDROID_HOME) points to your Android SDK directory (usually C:\Users\<YourUsername>\AppData\Local\Android\Sdk). Also add these paths to your system PATH:
    • %ANDROID_SDK_ROOT%\platform-tools
    • %ANDROID_SDK_ROOT%\tools\bin
      Test if adb works by running adb devices in Command Prompt—if it lists connected devices (even none, as long as no error), you’re good.
  • Node.js & Java Version Compatibility
    React Native requires LTS Node.js versions (18.x or 20.x are safe bets). For Java:
    • Android Studio Hedgehog (2023.1.1+) needs Java 17
    • Older Android Studio versions use Java 11
      Verify with node -v and java -version in CMD.
Fixes for Common Build Errors
  • Gradle Sync Failures/Timeouts
    Slow Gradle downloads or corrupted cache are frequent culprits:
    1. Delete the .gradle folder inside your project’s android directory, then re-run npx react-native run-android.
    2. Speed up Gradle by switching to domestic mirrors. Edit android\build.gradle and replace the repositories block with:
      repositories {
          maven { url 'https://maven.aliyun.com/repository/google' }
          maven { url 'https://maven.aliyun.com/repository/jcenter' }
          maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
      }
      
  • "Could not find com.android.tools.build:gradle:x.x.x"
    This means a mismatch between your Android Gradle Plugin version and Gradle version. Open android\gradle\wrapper\gradle-wrapper.properties to check your Gradle version (in distributionUrl), then match it with the correct plugin version in android\build.gradle (look for com.android.tools.build:gradle). You can reference the official version compatibility table directly in Android Studio’s documentation.
Fixes for Emulator Packaging/Running Issues
  • Emulator Won’t Start or Connect
    1. Open Android Studio’s AVD Manager, select your emulator, and click "Cold Boot Now"—sometimes a fresh boot fixes stuck emulators.
    2. Ensure your emulator’s API level matches your project’s compileSdkVersion and targetSdkVersion (set in android\app\build.gradle).
    3. Disable Hyper-V if it’s enabled—it conflicts with HAXM (Android’s emulator accelerator). Go to Control Panel > Programs > Turn Windows features on or off, uncheck Hyper-V, restart your PC, then try again.
  • "Failed to install the app" Error
    1. Confirm your emulator is running and detected: run adb devices to see if its ID shows up.
    2. Clean your project cache with npx react-native clean, then rebuild.
    3. Check permissions in android\app\src\main\AndroidManifest.xml—make sure you have <uses-permission android:name="android.permission.INTERNET" /> (React Native requires this by default).
If Nothing Works, Grab Specific Error Logs

When you run npx react-native run-android, copy the full error output from the console—focus on the final red error messages. Whether it’s a missing dependency, permission issue, or emulator connection problem, specific logs will help pinpoint the exact issue way faster.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:06:31