Android Studio在添加GreenDao后出现Gradle‘s dependency cache may be corrupt (this sometimes occurs after a

在用Android Studio编译时,突然报错

Unable to find method ‘org.gradle.api.tasks.testing.Test.getTestClassesDirs()Lorg/gradle/api/file/FileCollection;’
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

搜索一番后,发现应该是AS和gradle本身的问题,将文件gradle-wrapper.properties中的

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

修改为

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

AS开始自己下载4.4版本的gradle包,下载完成后提示

Minimum supported Gradle version is 5.6.4. Current version is 4.4.
Please fix the project’s Gradle settings.
Fix Gradle wrapper and re-import project
Open Gradle wrapper properties
Gradle Settings.

选择

Fix Gradle wrapper and re-import project

自动修改为

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

重新下载6.5的gradle包,经过漫长的等待后,下载完成了,但是提示

Gradle could not start your build.
> Could not create service of type ChecksumService using BuildSessionScopeServices.createChecksumService().
   > Timeout waiting to lock checksums cache (/Volumes/mac-data/workshop/zz-android/.gradle/checksums). It is currently in use by another Gradle instance.
     Owner PID: unknown
     Our PID: 36810
     Owner Operation: unknown
     Our operation: 
     Lock file: /Volumes/mac-data/workshop/zz-android/.gradle/checksums/checksums.lock

手动删除 /Volumes/mac-data/workshop/zz-android/.gradle/checksums/checksums.lock这个文件后,又出现了刚才一模一样的问题,由于我刚添加了GreenDao到Gradle 文件中,所以根据提示,我检查了一下版本,发现应该是GreenDao的版本问题,因为Gradle 在版本5.0以后有比较大 的改动,存在跟其它文件不兼容的问题,修改

classpath 'org.greenrobot:greendao-gradle-plugin:3.2.0'

classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0'

后问题解决.

总结

出现了上述问题后,先不用着急,可以试着把添加的plugin或者依赖的版本改为最新试试.

参考:

https://stackoverflow.com/questions/50122867/gradle-build-fails-unable-to-find-method-org-gradle-api-tasks-testing-test-get

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值