执行react-native run-android时React Native安卓构建报错:无法查询Provider值
React Native 安卓构建失败:Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'
报错信息
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'. > Cannot query the value of this provider because it has no value available.
已完成的排查步骤
- 执行
react-native doctor并修复了所有检测到的问题 - 确认Android SDK配置正确,
ANDROID_HOME、PATH环境变量设置无误 - 检查调试构建配置,未发现Gradle设置有明显异常
可能的解决方案
- 清理Gradle缓存与构建文件:在项目的
android目录下执行./gradlew clean,然后删除项目根目录的.gradle文件夹,再重新运行react-native run-android - 检查依赖版本兼容性:核对
android/app/build.gradle中的compileSdkVersion、targetSdkVersion是否与当前React Native版本要求一致;排查第三方依赖是否存在版本冲突,可尝试临时移除最近添加的依赖再测试构建 - 重置前端依赖:删除项目根目录的
node_modules、package-lock.json(或yarn.lock),执行npm install(或yarn install)重新安装依赖后重试 - 验证Gradle版本匹配:查看
android/gradle/wrapper/gradle-wrapper.properties中的distributionUrl,确认Gradle版本与Android Studio的Gradle插件版本兼容,必要时更新到对应兼容版本 - 检查Java版本:React Native 0.70及以上版本要求使用Java 11,通过
java -version确认本地Java版本符合要求,若不符则切换到对应版本
内容的提问来源于stack exchange,提问作者Manan Bhasin
相关产品推荐
相关产品推荐

