在用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:In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes
- 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.
搜索一番后,发现应该是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