关于android:Gradle的依赖项缓存可能已损坏

Gradle's dependency cache may be corrupt

我已经尝试失效/缓存并重新启动

还试图删除.gradle和gradle文件。
但是这个问题仍然出现。

Error:Unable to find method
'com.android.build.gradle.BaseExtension.getTestVariants()Lorg/gradle/api/internal/DefaultDomainObjectSet;'.
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.

有什么想法吗?

感谢您的帮助!


我认为您的kotlin-gradle-plugin版本较低;您可以尝试在project / build.gradle中更新您的kotlin-gradle-plugin

1
2
3
4
    dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
    classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4'}


您需要在gradle scripts中的gradle-wrapper.properties中更改distributionUrl。并且可以解决此错误。

1
2
3
4
5
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\\://services.gradle.org/distributions/gradle-3.4.1-all.zip

我有同样的错误。我通过更改gradle-wrapper.properties中的gradle分发版本来解决了此错误(您可以在https://services.gradle.org/distributions/中找到分发列表)

gradle-wrapper.properties

对于我的旧版本gradle分发示例:

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

我的新版本gradle发行版:

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

通过更改此版本,android studio将下载新的gradle分发并与项目同步。
这是gradle-wrapper.properties的位置


删除/.gradle/文件夹和/ gradle /文件夹,然后重新导入。或者,对于IntelliJ,您可以单击Gradle Tool窗口,然后单击Refresh。


尝试将gradle重置为可以正确加载的旧版本。在gradle脚本中更改gradle-wrapper.properties中的distributionUrl。并且可以解决此错误。


我有一个类似的问题,具有以下症状:

  • 我试图从项目中删除.gradle文件夹-它不起作用。
  • 我尝试使用旧的gradle版本,但是studio强迫我使用gradle-3.3,所以很长一段时间让我感到困惑。
  • 我注意到提示解压缩异常:

    java.util.zip.ZipException: error in opening zip file

    我试图手动解压缩文件,但说无法解压缩,因此问题一定是在下载过程中发生的。

  • 我的解决方案:
    我从设法成功构建的同事那里复制了文件gradle-3.3-all.zip,并在以下路径中替换了我的文件:

    1
    .gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zip