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

React Native运行Android时出现Build Gradle Error: 找不到'compile'未知属性报错

报错原因

该错误由Gradle版本不兼容导致:Gradle 3.0 版本开始就已废弃依赖声明关键字compile,推荐使用implementation或api替代,Gradle 7.0 及以上版本直接移除了compile的支持,因此构建时读取build.gradle中的compile配置会识别失败。

修复步骤
  • 打开报错的构建文件C:\dev\icnet_final\android\app\build.gradle,定位到第213行
  • 将该行的compile关键字替换为implementation即可,如果该依赖需要暴露给项目内其他依赖该模块的组件使用,可替换为api
  • 全局检索整个项目android目录下所有.gradle文件,将其余旧依赖声明关键字同步替换:testCompile替换为testImplementation、androidTestCompile替换为androidTestImplementation
  • 清理构建缓存后重新运行项目:Windows环境下进入android目录执行gradlew clean命令,再重新启动React Native Android端运行即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 08:36:05