10
votes

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!

7
Do you mean .gradle in the project directory or the user home directory? A full clean might be to do git clean -dfx and rm -rf ~/.gradle (assuming you don't have a gradle.properties file there). Then kill off any daemons or run with --no-daemon - Ben Manes
Thanks. already solved this problem. The file happened to be corrupted. - Emmanuel Deiparine
@EmmanuelDeiparine I'm also facing the same issue. Will you please tell how you solved the issue. Thanks. - Prashant Yadav
Build>Clean Project resolved my issue. - Kamran Bigdely

7 Answers

2
votes

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

1
votes

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.

1
votes

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
1
votes

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

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

0
votes

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.

-1
votes

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