升级gradle 4.0.0 出现Unable to find method org.gradle.api.tasks.TaskInputs.file

今日将Android Studio 升级到了4.0,同时也将 Gradle 升级到了 4.0.0。项目配置如下:
project 下的 build.gradle

dependencies {
    classpath 'com.android.tools.build:gradle:4.0.0' //升级到了4.0.0
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'org.greenrobot:greendao-gradle-plugin:3.2.0' //本地Greendao数据库
}

升级后,可以发现 gradle-wrapper.properties 文件下变成了 gradle-6.1.1

#Mon Jun 15 11:03:12 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

这时候,sync project,发现出现报错:

Unable to find method 'org.gradle.api.tasks.TaskInputs.file(Ljava/lang/Object;)Lorg/gradle/api/tasks/TaskInputs;'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

错误分析:

  1. Gradle的依赖缓存可能损坏(可能是由于网络连接超时导致)。
  2. Gradle构建过程(守护进程)的状态可能被破坏。停止所有的Gradle守护进程可以解决这个问题。
  3. 项目中使用的第三方插件与项目中的其他插件或项目所要求的Gradle版本不兼容。

其中错误1与错误2,AS 都有智能的修复方法,尝试了一遍,发现报错依旧存在,这样,产生报错的原因基本是错误三导致的,也就是“三方库与我们的项目 gradle 不兼容”,细想一下由于AS 4.0 也是刚出来,我算更新比较早的,这样三方库与gradle不兼容发生的概率很高。
在我的项目中,主要三方库就是 GreenDao,查看一下有没有出来新的版本,发现真的有版本更新(3.3.0)
所以,将 GreenDao 版本从 3.2.0 更新升级至 3.3.0, sync project,报错消失。

总结:如果你是近期更新了AS到4.0版本以及将 Gradle 升级到了 4.0.0 后遇到了该问题,那么检查升级一下 GreenDao 版本吧!
如果不是,那就根据错误1、2、3分析,一步一步排查问题吧,大概率就是你的三方库与 Gradle 版本不兼容。

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值