16

enter image description here

> Error:Failed to open zip file. Gradle's dependency cache may be
> corrupt (this sometimes occurs after a network connection timeout.) <a
> href="syncProject">Re-download dependencies and sync project (requires
> network)</a> <a href="syncProject">Re-download dependencies and sync
> project (requires network)</a>
Ojonugwa Jude Ochalifu
  • 23,935
  • 25
  • 104
  • 122
Khaled Mohsen
  • 171
  • 1
  • 1
  • 4
  • Have you tried to clean project, build -> clean – maytham-ɯɐɥʇʎɐɯ Mar 04 '17 at 12:51
  • 1
    just click on the error message that says **re-download...** and wait until it finishes downloading and installing. and while doing so make sure you have a stable network connection – phoenix Mar 04 '17 at 12:52
  • @Mr.Rabbit i do this but he field .... and i dont what i do – Khaled Mohsen Mar 04 '17 at 13:02
  • 1
    I have 2.2.3 to 2.3 updating error. I installed the Android Studio 2.3 again. – Roma Darvish Mar 04 '17 at 13:08
  • @Mr.Rabbit I tried what you said but it does nothing... – HQuser Mar 05 '17 at 05:34
  • OK. One thing you can try is delete all the files from cache folder of gradle. and then when you try to rebuild your project android studio will prompt you to install the dependencies again. path for the cache folder: **home/.gradle/caches/** .P.S: It's hidden by default. – phoenix Mar 05 '17 at 06:37
  • In these situations File --> Invalidate Caches/Restart... --> Invalidate and Restart works for me. – Nemus Mar 06 '17 at 03:06
  • Possible duplicate of [Error:Failed to open zip file. Gradle's dependency cache may be corrupt](http://stackoverflow.com/questions/42652980/errorfailed-to-open-zip-file-gradles-dependency-cache-may-be-corrupt) – Md Imran Choudhury May 04 '17 at 16:22
  • The answer is in the below link: https://stackoverflow.com/a/44205838/7663327 – Kerelos Jun 07 '17 at 23:22

11 Answers11

34

Find 'gradle-wrapper.properties' in root project

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

Change "https" to "http".

pls see the picture.enter image description here

Eric MaCarthy
  • 498
  • 4
  • 8
  • 2
    Thanks , Worked for me , just replace https to http – iamkdblue Jun 23 '18 at 04:47
  • 1
    but what are the implications? This seems more like a hack since we are compromising on SSL end point – Sudip Bhandari Sep 24 '18 at 12:29
  • 1
    thanks perfect fix... but it is unfortunate that the default blank activity app has this issue... – Antonin GAVREL Dec 12 '18 at 15:10
  • In my case `distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-all.zip` was throwing the same error posted in the question. Now with `distributionUrl=http\://services.gradle.org/distributions/gradle-5.4-all.zip` it says `Gradle Sync: Download http://services.gradle.org/distributions/gradle-5.4-all.zip`. It looks like it is fixing it for me too. – Jaime Montoya May 13 '19 at 17:22
  • I tried this steps In android studio 3.6.1 but it failed with: 7:38 PM Gradle sync failed: Server returned HTTP response code: 403 for URL: http://services.gradle.org/distributions/gradle-5.6.4-all.zip – negrotico19 Mar 23 '21 at 01:39
14

go to the "home.gradle\wrapper\dists" folder and cut/delete the "gradle-3.3-all" folder, now rebulid the project. This should resolve the issue, as it worked for me.

6

I face this problem after updating Android Studio from 2.2.3 to 2.3;

Solution

1) In your project open 'gradle-wrapper.properties', change the 'distributionUrl' value

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

2) In you project open the project's 'build.gradle' file, and change the classpath

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

3) At last Sync your project.

(This is the latest gradle setting.)

Dharman
  • 21,838
  • 18
  • 57
  • 107
Sankar Behera
  • 753
  • 9
  • 10
4

Step 1 Go to your dir (cd ~) and do ls -la , It will show you .gradle folder. Do cd .gradle/wrapper/dists/gradle-3.3-all and check it premission

provide full permission

sudo chmod -R 777 .gradle/

it will provide full permision to .gradle folder

Step 2 delete the previous one

rm -rf .gradle/wrapper/dists/gradle-3.3-all/

Step 3 Use Restart and invalidate option of Android Studio it will clear previous cache and download fresh gradle-3.3-all file

step 4 Please keep your internet connection proper with good speed. it will download all required file. This issue gennerally comes when your internet connection is not stable or have slow sped. I am saying this as per error log given by AS. Error:Failed to open zip file.

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a>
<a href="syncProject">Re-download dependencies and sync project (requires network)</a>
Dharman
  • 21,838
  • 18
  • 57
  • 107
SAURABH_12
  • 2,093
  • 1
  • 17
  • 19
4

If everything else fails, an option is to use a local distribution of gradle.

Download a zipped version of Gradle.

unzip it and place it in a directory. Preferably C:\Program Files\Android\Android Studio\gradle

As at time of writing, I am using gradle-3.4.1-bin

Then, direct gradle to this directory:

File > Settings > Gradle > use local gradle distribution

enter image description here

Sync your project and you are good to go.

Note: Although it is recommended to use the default gradle wrapper, this option is fine.The only "problem" is you have to manually track updates etc

Ojonugwa Jude Ochalifu
  • 23,935
  • 25
  • 104
  • 122
2

In order to solve it:

  1. Go to gradle-wrapper.properties from the "project" side menu

  2. Change: distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip to distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip

After this studio should be able to download the correct zip file i.e. "gradle-3.3-all.zip".

If this does not help then you will have to make a few efforts:

  1. Download the zip file manually from gradle-3.3-all.zip
  2. Copy the zip file.
  3. Reach the directory wherever your ".gradle" folder exists. It's usually in "C:\Users\user.gradle", if you are on windows.
  4. Navigate to "wrapper" and then to "gradle-3.3-all".
  5. Replace the zip file already there with the newly downloaded zip file.

enter image description here

KenHBS
  • 5,620
  • 6
  • 30
  • 42
Tinh Xuan
  • 187
  • 1
  • 3
2

for mac user just go to the ~/.gradle/wrapper/dists and delete all the folders there
for more explanation follow the detail below

  • open finder
  • Go -> Go to Folder
  • type ~/.gradle/wrapper/dists and press enter
  • delete all the folders in it
  • now, restart android studio, it will download all the files again
Sultan Ali
  • 1,853
  • 23
  • 21
1

this case appear to me when try to open another project that I download it from github so I just change all gradle files in all project to the latest gradle build

  1. build.gradle --> module app // compileSdkVersion and buildToolsVersion
  2. build.gradle --> project // classpath 'com.android.tools.build:gradle:currentVersion
  3. build.gradle --> library is exist.
  4. gradle-wrapper.properties --> be accurate to check the distributionUrl is start with https not http

all of this solve the problem for me ..

Mina Samir
  • 817
  • 9
  • 11
1

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

sana ebadi
  • 4,318
  • 29
  • 36
0

I faced the same issue 4 days ago and today I was able to solve it by changing the

Compile Sdk Version to 26

Target Sdk Version to 26

Min Sdk Version to 26

Build Tools Version to 28

by going to

    File > Project Structure > 

enter image description here

enter image description here

What did not work::

  1. deleting .gradle folder
  2. downloading gradle with Android studio
  3. downloading gradle manually
  4. Updating Android studio
Jude
  • 386
  • 1
  • 3
  • 9
0

On macbook. user just go to the ~/.gradle/wrapper/dists and delete all the folders there for more explanation follow the detail below

  1. open finder
  2. Go -> Go to Folder
  3. type ~/.gradle/wrapper/dists and press enter
  4. delete all the folders in it
  5. now, restart android studio, it will download all the files again