Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Asked Answered
A

41

113

I am getting this kind of error, how to fix it.

Error:Unable to load class 'org.gradle.tooling.internal.protocol.test.InternalTestExecutionConnection'.
Possible causes for this unexpected error 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.
Antananarivo answered 18/7, 2016 at 17:41 Comment(2)
Please check my answer. In my case it was JDK path issue. https://mcmap.net/q/195663/-android-gradle-39-s-dependency-cache-may-be-corrupt-and-gradle-build-not-workingPsaltery
the problem occurs when internet disconnects in the middle of your gradle download. so go to the C:\Users\your username\.gradle\wrapper\dists\gradle-6.5-bin and delete the zip file. Reopen the project and gradle will start to download 100mb file again.Chadbourne
D
195

I updated my Android Studio to 2.3 and it asked me to update my gradle plugin to 3.3 that created issues with my running projects. I've gone through all the Stack solutions and nothing worked for me except this workaround: I changed my distribution url in gradle-wrapper.properties with this one.

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

(permanent link list here : https://services.gradle.org/distributions/)

My project is up and running.It just asked me to update to gradle build tools 25.0.0 which I did so. Everything is fine now :)

  1. Go to the project section and select gradle scripts menu.
  2. Under script, menu select gradle -wrapper.properties
  3. Then replace the distributionUrl=https://services.gradle.org/distributions/gradle-2.2-all.zip with "distributionUrl=https://services.gradle.org/distributions/gradle-3.4.1-all.zip"

enter image description here note: distributions gradle will change depended upon the version of the android studio.

Daggna answered 6/3, 2017 at 9:50 Comment(7)
Perfect solution, worked for me after days of search. Thanks.Castilian
Where gradle-wrapper.properties found? All I see is a jar fileWeeds
It's in your project's Gradle folder hierarchy.Daggna
Thanks! But the problem persists after initializing every new project. It there a permanent fix?Neilson
For anyone updating this in the future, the list of Gradle versions can be found here: services.gradle.org/distributions Just right click and save link location to use the String in your gradle file.Ozenfant
gradle-6.2.2-all.zip fixed the issue for Android Studio 3.6.1Rebutter
If someone find it difficult to get the version number, here's a simple trick that will work for you. Just create a new project, Go to its gradle-wrapper.properties file and copy the version from there.Purity
S
69

Make sure you have Internet Connection then:

1.For Window Users Go to > C:\Users\username\.gradle\wrapper\dists

2.For Linux users Go to $HOME/.gradle (~/.gradle) and/or (Under Specific project) <PROJECT_DIR>/.gradle

3.Delete the gradle file(s) with the problem(i.e the zipped folders with missing with no its extracted file )

4.Sync the project with gradle files.

Scrutineer answered 11/11, 2017 at 10:16 Comment(1)
In my case, the internet cut out while downloading Gradle. Clicking "Try Again" did nothing (on Android Studio 3.1.3). Deleting the C:\Users\username\.gradle\wrapper\dists folder did fix it and allow it to download again.Stalactite
S
27

Delete corrupt files

This error occurs when Gradle files are not completely downloaded or corrupted by some other reason, so we have to redownload the files. The easy way is to delete the old files in

C:\Users\username.gradle\wrapper\dists

and rebuild the project, Android Studio will automatically download the new files.

Solifidian answered 21/4, 2018 at 5:42 Comment(2)
Thanks for sharing, it was always failing to download with me, so even if i changed the version, that wouldn't help, but deleting the files and trying again, worked, thanks.Submersed
In my case, it did not work. I tried to delete the files still I'm facing the same issue.Counterpane
M
14

Watch the Tutorial https://www.youtube.com/watch?v=u92_73vfA8M

or

follow steps :

  1. Go to any browser

  2. type gradle and press enter

you can specify any version you want after the

gradle keyword

i am downloading gradle 3.3

  1. https://services.gradle.org/distributions click on this link which is in description directly if you want

  2. click on gradle 3.3 all.zip

  3. wait for the download to complete

  4. once the download is complete extract the file to the location

c://user/your pc name /.gradle/wrapper/dists

  1. wait till extraction it takes 5 mins to complete

  2. Now open your project in android studio

9.go to file > settings >bulid ,exec,deployment > gradle

  1. now change use default gradle to

use local gradle distributn

select the location where you had extracted gradle 3.3.zip

C:\Users\your pc name.gradle\wrapper\dists\gradle-3.3

  1. click on OK

  2. Now build starts again and

you can see now the build is successful and error is resolved

Maimaia answered 4/4, 2017 at 11:13 Comment(3)
this answer should cover every flow of the problemYeta
Why do we need the browser?Memorandum
to download the gradle file locally for the subsequent builds locallyMaimaia
G
7

If you manually setup gradle also make sure projects build.gradle verison is compatible with it. See following as an example.

Project's build.gradle

dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
    }

Manual gradle setup

Manual gradle setup

Germiston answered 30/6, 2017 at 23:51 Comment(0)
C
7

A lot of answer to this questions but a few were helping. I want to give accurate and updated answer.

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

This error happens when you bad internet connection or you put your computer to sleep while Android Studio is downloading the required dependencies.

How to resolve this issue.

  1. Find out the project's Gradle version. You will find that in gradle-wrapper.properties in distributionUrl my gradle distribution was https\://services.gradle.org/distributions/gradle-6.5-all.zip that means gradle-6.5-all.zip is required to download and right now it is corrupted because of connection timeout. Lets find out this folder and delete this.
  2. Go to $HOME/.gradle folder then to wrapper then to dists then find a folder that matches the gradle version name that required to download. In my case it was gradle-6.5-all.zip select this folder and delete it.
  3. Now sync the project and make sure you have good internet connection and setting that will prevent your system going to sleep while downloading something.
Cannibalize answered 2/9, 2020 at 6:55 Comment(2)
The only answer that doesn't mess with the generated gradle filesQuarrelsome
This is right answer .Minnick
H
6

Kindly delele all folders under the in /.graddle/version/

This is how i solved mine. good luck

Hoo answered 22/7, 2016 at 10:47 Comment(0)
T
5

Maybe you can run ./gradlew build -s in the terminal, the stacktrace would show you where went wrong.

Tel answered 14/2, 2019 at 8:34 Comment(2)
In my case, I found that one of my repositories failed, causing gson dependency download failedTel
This command help me find the correct corrupted gradle file.Obligee
Q
4

Try the next step to "Refresh" your IDE (android studio)

1. Let Gradle rebuild your auto-genrated files by click Build | Rebuild
2. Also try Choose File | Invalidate Caches/Restart.

Quindecennial answered 18/7, 2016 at 19:46 Comment(1)
If doesn't work - Please provide your Gradle logs after doing this.Quindecennial
K
4

I resolved this issue by downloading current version of graddle from link given download latest version of graddle possibly graddle 3.3

Then in next step i accessed .graddle/wrapper/dists dirctory from home directory on my Mac after showing up hidden system files and deleted previuos version folder residing there.

Now i put that downloaded latest version folder after uncompressing there. Now restarted Android studio and problem was resolved.

Kandi answered 20/1, 2017 at 8:1 Comment(0)
P
3

i deleted the gradle folder and then i did rebuild, every thing working fine

Pastoralist answered 26/4, 2020 at 11:33 Comment(0)
M
3

If you are seeing this error in Android Studio 4.1 with Gradle 6.5 then you should move back to

classpath 'com.android.tools.build:gradle:4.0.2'

For some reason

classpath 'com.android.tools.build:gradle:4.2.0'

does not work correctly.

Mirza answered 3/11, 2020 at 14:43 Comment(2)
Thank You. its working. classpath "com.android.tools.build:gradle:4.1.1"Currajong
In my case I actually needed to change it to 4.2.0. My build.grade file was still set at 3.4 after updating Android Studio.Matins
C
2

You can try this

  1. first Open your Android Studio > open any project you're doing
  2. click on File > Settings > Build,Execution,Deployment > Gradle
  3. At Project-Level settings , there are 2 option to sync the gradle either usin the default or local.
  4. now change from default to a local gradle distribution > gradle Home

  5. select the path on your computer.

C:\Program Files\Android\Android Studio\gradle\gradle-4.1

  1. click on OK

  2. Now build starts again it should be solved.

Chestonchest answered 5/12, 2017 at 10:2 Comment(0)
N
2

Go to "C:\Users\.gradle\caches\". Delete all the files in the folder. Then Sync Gradle and Rebuild the project.

Nitrobacteria answered 19/1, 2020 at 3:48 Comment(1)
thank you. at least 4 hours I tried to solve this problem, every solution on stackoverflow is failed except this.Apples
C
2

If you using Ubuntu, So firstly you have unhide all files from your home directory or where located your android studio folder :

  1. Go to your home directory and unhide all files by using ctrl+h
  2. You found .gradle folder
  3. Inside .gradle -> wrapper
  4. You can found dists folder, So delete this dists folder
  5. Create a New Project than your Gradle file re-downloaded
  6. Congo you successfully build project
Correct answered 2/6, 2020 at 6:20 Comment(0)
G
1

check out distributionUrl setting in gradle-wrapper.properties. I changed https to http, then my problem was solved.

Giefer answered 17/2, 2017 at 8:20 Comment(0)
P
1

In my case,just change http to https in the gradle-wrapper and Sync it.

Powys answered 1/3, 2017 at 10:46 Comment(0)
G
1

Just reimport project. :) I tried cleaning up the cache and refreshing dependencies doesn't work but failed.

Grasmere answered 19/5, 2017 at 21:36 Comment(1)
I had to delete and re-import my modulesSentry
A
1

Clear .gradle folder and rebuild

Autobiography answered 20/6, 2017 at 18:59 Comment(0)
C
1
  1. Open C:\Users\Username.gradle\wrapper\dists\

  2. Open latest gradle folder, e.g. gradle-4.1-rc-1-all

    You will find a random folder named 936kh1brdchce6fvd2c1o8t8x

  3. Download zip file of similar name

    eg: https://downloads.gradle.org/distributions/gradle-4.1-rc-1-all.zip

  4. Save it in this folder

  5. Restart Android studio

    It will automatically extract the zip folder and Error will clear

Caption answered 27/8, 2017 at 16:17 Comment(0)
D
1

Finally solved this problem.

If you just copy new version's files to old folder and override files,you may face the same question as me.

To solve it:

  1. makesure you saved your all settings.
  2. close AS,DELETE ALL files of your mixed version.
  3. extract new version to your empty folder.

It works for me.

Dioptrics answered 28/8, 2017 at 2:17 Comment(1)
Worked for me. App was being deployed through Self-Service which didn't bother to first clear out the old directory. Requesting them to do so fixed the issue. Thank you!Uncertain
M
1

For me, i was cloning a project from github which used a version of gradle higher than that which i had installed. I had two choices:

  1. Open gradle.wrapper-properties of a project you have that's building successfully, and copy the line that says distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip. Use this to replace the same value in the project that's failing. That should do the trick.

  2. Your build might still fail if the gradle version used to build the project is higher than that which you just added. For this you should update the gradle version to the latest.

Mucoprotein answered 4/12, 2019 at 16:3 Comment(0)
B
1

In my case I hade to change from:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    **apply plugin :'com.google.gms.google-services'**
}

to

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'com.google.gms.google-services'
}
Bellerophon answered 3/1, 2021 at 15:14 Comment(0)
G
1
  1. search on google "download java 11"
  2. click oracle website download your java to your platform and install it.
  3. go to android studio click CTRL+SHIFT+ALT(Project Structure)
  4. SDK Location Tab Show the path of JDK location which you installedenter image description here
Griswold answered 4/1, 2021 at 10:4 Comment(0)
H
1

In your gradle-wrapper.properties

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

This won't download and always gives 'gradle cache corrupt' error, but a small change makes it work fine

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

Now sync the gradle again and it's done.

Herodotus answered 1/2, 2021 at 18:3 Comment(0)
P
1

I will generalize the issue that you might face

Inside module's build.gradle :

Change:

plugins {
    [...]
    apply plugin:'whatever_you_have'
}

to

plugins {
    [...]
    id 'whatever_you_have'
}

In other words instead of apply plugin: use id

Parole answered 20/4, 2021 at 17:13 Comment(0)
S
1

Unable to find method ''void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)'' 'void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)'

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.

It happened to me after upgrading Android Studio to 4.2.0.

Updating the hilt classpath on build.gradle to 2.35 fixed these issues for me.

classpath "com.google.dagger:hilt-android-gradle-plugin:$2.35"
Sara answered 6/5, 2021 at 13:42 Comment(0)
N
1

I know I'm late to answer this question, but after searching for so long and checking each and every dependency the problem with me was I've promoted the Kotlin version but forgot to update the KSP version,

id 'com.google.devtools.ksp' version '1.8.20-1.0.11'

Please make sure this line should contain the same version as your Kotlin version

Hope this helps!

Naphthalene answered 22/4, 2023 at 23:34 Comment(0)
E
0

If you have updated your android studio, then go to FILE, Project Structure, Project, then check gradle version. Before that check your gradle version in C:\Program Files\Android\Android Studio\gradle and check the version if it matches then sync again else change the gradle version in android studio and sync again.

Extensible answered 15/3, 2017 at 21:46 Comment(0)
J
0

I had a similar problem after cloning AnySoftKeyboard and opening it in Android Studio. What worked for me was deleting the AynSoftKeyboard/gradle folder and then cleaning the project via menu item Build > Clean Project.

So try deleting YourProject/gradle folder and clean the project to trigger a Gradle sync.

Hope it works for your case.

Junction answered 28/3, 2017 at 9:43 Comment(0)
N
0

download gradle from here for your OS and extract the file and paste the inner folder into installLocation/gradle

than in Android Studio Goto File > Settings > bulid ,exec,deployment > gradle and choose local gradle option and provide the file path of your new downloaded gradle and hit ok it works :)

Nonstriated answered 18/4, 2017 at 16:20 Comment(0)
W
0
  1. delete C:\Users\Administrator.gradle\caches\xxx (xxx gradle version)
  2. rebuild
Watchmaker answered 24/4, 2017 at 3:36 Comment(0)
C
0

I had this problem i just deleted every thing related to android in c://user/your pc name / and it worked

Cerebrovascular answered 3/7, 2017 at 22:57 Comment(1)
i had the same problem and just deleted everything but still getting the same error.Creep
C
0

If it has happened after upgrading Android Studio, It can be caused by an out of date buildtool, Update Android SDK BuildTools

Conglobate answered 6/8, 2017 at 9:17 Comment(0)
C
0

For Mac users

  1. open /Users/username/.gradle/wrapper/dists
  2. Check the latest gradle-4.4-all inside that directory
  3. Use the latest version and put it to gradle-wrapper.properties in Android Studio Project

In my case I was using distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip that is why I get the issue.

I change it to distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip and just sync again

Commutator answered 16/7, 2018 at 6:43 Comment(0)
M
0

Sometime problem is gradle wrapper file inside your project file. Open your current project gradle file and delete gradle wrapper.zip file and then sync project this will work.

Minus answered 14/9, 2018 at 2:27 Comment(0)
D
0

In my case the reason was in this line:

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.

My project used a third-party plugin, that is incompatible with the newest gradle plugin version. So updating plugins versions may help to solve the issue.

Darken answered 4/8, 2020 at 15:1 Comment(1)
which plugin was it?Mirza
F
0

I faced the same issue, I opened the file: my-project/gradle/wrapper/gradle-wrapper.properties, replaced the distributionUrl to

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

I opened the file: my-project/build.gradle, under buildscript -> dependencies, replaced the classpath to

classpath 'com.android.tools.build:gradle:4.0.0'

Sync the project and worked fine

Fionnula answered 18/8, 2020 at 4:59 Comment(0)
C
0

Just delete gradle folder , and let android studio download it again with click on Sync now !.

Chumash answered 3/3, 2021 at 8:6 Comment(0)
Z
0

Now, In March-2021, gradle 3.4.1-all not worked for me, and arise corrpt error. So, I use in build.gradle (project:) the following elements:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }

        maven {
            url "https://s3.amazonaws.com/repo.commonsware.com"
        }
        maven { url "https://jitpack.io" }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.2'

        classpath 'com.google.gms:google-services:4.3.5' // If you use play service 

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
        maven {
            url "https://s3.amazonaws.com/repo.commonsware.com"
        }
        maven {
            url "https://maven.google.com"
        }
        maven { url "https://jitpack.io" }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Ziwot answered 17/4, 2021 at 16:23 Comment(0)
V
-1

This was my scenary: I had to use another Android Studio version (3.2.1) and the Gradle version was 4.6. For that, I downloaded the .zip version of Android Studio. At first it didn't work, even if I created a new project, Gradle wasn't working. But after some research and some help from this posts I did the following:

  1. I went to my gradle files route (android-studio\gradle) and deleted all the gradle-4.6 files.
  2. After that I went to gradle-wrapper.properties and got the Gradle version that I needed (gradle-4.6-all.zip).
  3. I went to the gradle site and look for the version that I needed.
  4. Downloaded and unziped it into my Android Studio's gradle file route, look step 1.
  5. I went to Android Studio settings (file/settings/Gradle) and change the option "Use default gradle wrapper (recommended)" to "Use local gradle distribution".
  6. I selected the route where I downloaded the Gradle version, that's step 4, and applied changes.
  7. Just in case, I used the "Invalidate Cache / Restart" option (file/ "Invalidate Cache / Restart").
  8. After that I used the "Sync project and Gradle files" and worked!

By the way, I am using Android Studio 3.2.1 zip version. I had the same problem when I tried to create projects with older Android Studio.

Vaal answered 19/6, 2019 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.