3

I am facing Gradle cache error and I don't know how to tackle it. I have attached the error snap with my question below. I tried different solutions posted at stack-overflow but none of them worked. Anyone suggest me a solution Any additional suggestions would be helpful.

e.g Error: Failed to open zip file.e.g Error: Failed to open zip file.

enter image description here

Community
  • 1
  • 1
Zaigham Raza
  • 336
  • 2
  • 3
  • 14
  • Possible duplicate of [Error:Failed to open zip file. Gradle dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)](http://stackoverflow.com/questions/41789809/errorfailed-to-open-zip-file-gradle-dependency-cache-may-be-corrupt-this-some) – Md Imran Choudhury Apr 17 '17 at 14:41
  • check this answer https://stackoverflow.com/a/48360984/4797289 – Rasoul Miri May 16 '20 at 06:59

10 Answers10

3
  • Download the latest gradle package from this directory
  • Extract it and put it somewhere (for example f:\gradle-1.10)
  • Go to your Android Studio and load your project then open File->Settings->gradle, in this page click on Use local gradle distribution.
  • Type your gradle folder address there.

enter image description here

Zaigham Raza
  • 336
  • 2
  • 3
  • 14
2

Its because your gradle directory is not the directory of your gradle, to check go to android studio open your project then open File->Settings->Build,Execution, Deployment->Gradle

https://i.stack.imgur.com/wVFyh.png

2

Hey not necessary to set gradle manually. i have also faced this issue but i deleted all files in gradle folder path "C:/Users/username/.gradle/" simple steps follow

  1. first goto path "C:/Users/username/.gradle/"
  2. delete all files in above path.
  3. open android studio and sync gradle or build again or create new project.
  4. it will be auto downloaded new gradle version files and auto build.

*Make sure you your gradle settings like this - checked "Use default gradle wrapper(recommended) - unchecked offline work

2

You can download manually but this is another solution: Change "https" to "http" on 'gradle-wrapper.properties' in root project.

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
to,
distributionUrl=http\://services.gradle.org/distributions/gradle-3.3-all.zip
Md Imran Choudhury
  • 6,954
  • 2
  • 45
  • 50
1
  1. first :i tried to delete the .gradle folder from project it doesn't work;
  2. second: i tried use the old version gradle ,but studio force me to use gradle-3.3,so it confused me long time;
  3. third:I noticed the tips unzip exception"java.util.zip.ZipException: error in opening zip file", I tried to unzip the file by handset's really can't unzip, so the problem must happen in the download process.

solution: I copy the file "gradle-3.3-all.zip " from my colleague who build success,and replace mine in such path ".gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zip "

kan137g
  • 31
  • 3
1

If you want to use gradle wrapper - delete anything under:

.gradle/wrapper/dists/

and refresh gradle. The gradle wrapper will download from scratch and everything should work fine.

Elyran
  • 203
  • 2
  • 10
0

I solved this problem with the installation of Gradle using HomeBrew on Mac. If you type gradle -v in terminal and shows command not found: gradle, then I think you can use this way to solve this problem on Mac:

  1. First install the Gradle with Homebrew: brew install gradle

  2. Then go to Android Studio, open Android Studio->Preferences->Build,Execution,Deployment->Gradle, under Project-level settings check: Use local gradle distribution and set Gradle home with: '/usr/local/Cellar/gradle/3.5/libexec' (3.5 is my gradle version)

  3. Try again, and if the version is not correct, you can manually download the specified version from gradle website (the version specified in the file <your project dir>/gradle/wrapper/gradle-wrapper.properties: distributionUrl=<url>), extract the downloaded zip file to the location and set the Gradle home to it in Android Studio.

Hope that helps.

SpkingR
  • 805
  • 7
  • 13
0

From my MAC i just go to the gradle folder (/Users/USER/.gradle) > wrapper > dist and delete the gradle folder with the problem. Then go to studio and re-download the gradle file.

user1935005
  • 46
  • 1
  • 2
0

In my case, I changed distributionUrl in gradle-wrapper.properties from

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

to

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

Gpak
  • 1,056
  • 12
  • 18
0
cd /root/.gradle/wrapper/dists
ls
gradle-5.6.4-all  gradle-6.5-all  gradle-6.6.1-bin
gradle-6.1.1-bin  gradle-6.5-bin

for example (gradle-6.1.1-bin) :

rm -R gradle-6.1.1-bin