Gradle常见问题及总结

使用android studio开发项目,难免遇到gradle相关的错误,在此总结。

gradle插件与gradle home版本关系错误

参考更新 Gradle
插件版本	所需的最低 Gradle 版本

Gradle下载太慢

Index of /gradle/ (tencent.com) 是国内下载地址,手动下载对应版本即可

缓存不刷新

问题描述
maven发布了一个aar,本地gradle始终同步不下来
问题解决
找到 aar对应的xml配置,在这个目录下:根工程/.idea/libraries/Gradle_aaraname_aar.xml
删除以下文件
Build/clean project
Build/rebuild project
File/Sync Project with Gradle Files
File/invalate cache

Executionfailed forJetifyTransform:xx.jar

问题描述
在导入了一个jar包到Android工程中,遇到了如下错误: Executionfailed forJetifyTransform:xx.jar Failedto transform 'xx.jar'usingJetifier.Reason:3.

问题解决
查询原因是jar包在jetified转换失败了,如果当前的库不需要被jetified处理,不往AndroidX中迁移这个包,则可以将当前jar包剔除转换,方法是在gradle.properties文件中配置黑名单,如下:

android.nonTransitiveRClass=true
android.jetifier.blacklist = xx.jar

然后再重新同步gradle,重新构建,问题解决。

Failed to transform file ‘xxxxx.jar‘ to match attributes

问题描述
maven上的某aar自动更新,该aar使用了非android的aar,导致项目编译不过

问题解决

经排查是新建的项目的gradlew.properties文件中都是默认配置支持androidx:

android.useAndroidX=true
#Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

第二句的注释意思是把第三方的libs都会自动转换成androidx,有些sdk未作这块的兼容适配,就会爆出上面的错误

只需将第二句改为false即可:

android.enableJetifier=false

Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.

问题描述

.gradle/caches/modules-2/files-2.1/com.squareup.retrofit2/retrofit/2.11.0/6ca8c6caf842271f3232e075519fe04081ef7069/retrofit-2.11.0.jar!/META-INF/retrofit.kotlin_module: 

kotlin插件版本与gradle插件版本不匹配

问题解决

解决1:升级gradle home 版本
kotlin 1.6.0对应gradle home版本为6.8.3,gradle插件版本为4.2.2

 classpath 'com.android.tools.build:gradle:4.2.2'
 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0"
 classpath "org.jetbrains.kotlin:kotlin-android-extensions:1.9.0"

Task :prepareKotlinBuildScriptModel UP-TO-DATE

问题描述:
gradle日志如下

Task :prepareKotlinBuildScriptModel UP-TO-DATE
IOException: https://dl.google.com/android/repository/addons_list-3.xml
java.net.ConnectException: Connection refused: connect
IOException: https://dl.google.com/android/repository/addons_list-2.xml
java.net.ConnectException: Connection refused: connect
IOException: https://dl.google.com/android/repository/addons_list-1.xml
java.net.ConnectException: Connection refused: connect
Failed to download any source lists!

问题解决:
找到gradlehome安装路径->
删除gradle.properties 中android studio插入的代理配置->
重新编译

Android运行项目时提示:No signature of method: build_*.android() is applicable for argument types

问题描述
android代码块内部有错误
问题解决
方法体内的定义全部删除,尝试编译,若通过
进行逐行删除,直至找到影响编译的代码块

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值