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

执行npx react-native run-android命令时遇Gradle构建失败问题

解决npx react-native run-android构建失败问题

错误信息

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project 'AwesomeProject'.
    Could not determine the dependencies of task ':gradle-plugin:react-native-gradle-plugin:compileKotlin'.
    Service 'SystemInfo' is not available (os=Windows 11 10.0 amd64, enabled=false).

已知清理Gradle缓存无效,可尝试以下方案:

  • 启用Windows关键服务
    按Win + R输入services.msc打开服务列表,找到Windows Management Instrumentation服务,确保它处于运行状态,启动类型设为自动。未运行则右键启动,已运行则先重启再尝试构建。

  • 调整Gradle配置
    在项目根目录的gradle.properties文件中添加以下配置:

    org.gradle.jvmargs=-Xmx2048m --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.rmi/sun.rmi.transport=ALL-UNNAMED
    

    同时确认项目build.gradle中使用的Gradle版本与当前React Native版本兼容(如RN 0.7x建议用Gradle 7.x或8.x)。

  • 检查JDK版本
    用java -version命令查看本地JDK版本,React Native 0.70+要求使用JDK 11,版本不符则切换到对应版本后重新构建。

  • 重置React Native缓存
    执行以下命令清理RN相关缓存:

    npx react-native start --reset-cache
    

    完成后重新运行npx react-native run-android。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 09:23:16