Emmanuel Deiparine
Emmanuel Deiparine

Reputation: 129

Gradle's dependency cache may be corrupt

I already tried to Invalidate/Cache and restart

also tried to remove .gradle and gradle file.. but this problem still shows up.

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.

Any thoughts?

Your help will be appreciated Thanks!

Upvotes: 11

Views: 22513

Answers (8)

Ngalonde Marvin
Ngalonde Marvin

Reputation: 1

in the gradle-wrapper.properties I changed the "https" to http and everything worked perfect

distributionBase=GRADLE_USER_HOME
distributionUrl=http\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

Upvotes: 0

Zain
Zain

Reputation: 40810

Tried to manually download the gradle, and clear gradle distributions in C:\Users\myUserName\.gradle\wrapper\dists.. Nothing worked.

The only thing worked for me is to install java JDK 11, then set it in

File > Project Structure -> SDK location -> JDK location

enter image description here

And then redownload the gradle distribution;

I am using Android Studio v4.2, so it may differ for lower versions.

Upvotes: 0

I have the same error. I solved this error by change version of gradle distribution in gradle-wrapper.properties (you can find list of distribution in https://services.gradle.org/distributions/)

gradle-wrapper.properties

For the example my old version gradle distribution:

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

My new version gradle distribution:

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

By changed this version, android studio will download the new of gradle disrtribution and sync with the project. This is the location of gradle-wrapper.properties

Upvotes: 2

Yasin Yao
Yasin Yao

Reputation: 11

I think your version of kotlin-gradle-plugin is low; you can try to update your kotlin-gradle-plugin in project/build.gradle

    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'}

Upvotes: 1

Muhammad Waleed
Muhammad Waleed

Reputation: 2601

You need to Change the distributionUrl in gradle-wrapper.properties in gradle scripts. And this error can be solved.

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

Upvotes: 0

Stevers
Stevers

Reputation: 535

Delete /.gradle/ folder and /gradle/ folder and reimport. Or in the case of IntelliJ, you can click the Gradle Tool window and click Refresh.

Upvotes: 0

kan137g
kan137g

Reputation: 41

I had a similar problem, with the following symptoms:

  1. I tried to delete the .gradle folder from project - it doesn't work.
  2. I tried use an old gradle version, but studio forced me to use gradle-3.3, so it confused me a long time.
  3. I noticed the tips unzip exception:

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

    I tried to unzip the file by hand, it said it couldn't unzip, so the problem must have happened in the download process.

My solution: I copied the file gradle-3.3-all.zip from my colleague who managed to build successfuly,and replaced mine in this path:

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

Upvotes: -1

Zeng Travis
Zeng Travis

Reputation: 11

Try to reset the gradle to an older version which you can load correctly. Change the distributionUrl in gradle-wrapper.properties in gradle scripts. And this error can be solved.

Upvotes: 1

Related Questions