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

主宰稳场 提交于 2019-11-26 21:47:21
Taimur Khan

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-3.4.1-all.zip

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"

note: distributions gradle will change depended upon the version of the android studio.

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.

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

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

This is how i solved mine. good luck

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

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.

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.

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.

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

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.

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

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

Clear .gradle folder and rebuild

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.

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.

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.

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 :)

  1. delete C:\Users\Administrator.gradle\caches\xxx (xxx gradle version)
  2. rebuild

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

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

Mugasho Lincoln
  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

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

Hope this will help.

thanks

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!