Android studio - Failed to complete gradle execution - error in opening zip file
Asked Answered
G

15

29

I'm new to android development and android studio IDE.

I've checked-out a project from bitbucket and when I try to compile it I get the following error:

Failed to complete Gradle Execution

Cause: error in opening zip file.

My gradle-wrapper.properties is as follows:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip

I wasn't able to get too much information from this but the full log states:

2014-05-23 14:06:28,950 [ 32077] WARN - nal.AbstractExternalSystemTask - Cause: error in opening zip file com.intellij.openapi.externalSystem.model.ExternalSystemException: Cause: error in opening zip file at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:206) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:116) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:64) at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:41) at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:37) at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:59) at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:37) at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:49) at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:48) at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:137) at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:123) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3.execute(ExternalSystemUtil.java:467) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$4$2.run(ExternalSystemUtil.java:546) at com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:464) at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178) at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212) at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171) at com.intellij.openapi.progress.impl.ProgressManagerImpl$8.run(ProgressManagerImpl.java:373) at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:419) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) at com.intellij.openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:149)

2014-05-23 14:06:28,950 [ 32077] WARN - .project.GradleProjectImporter - 2014-05-23 14:06:28,951 [ 32078]
INFO - .project.GradleProjectImporter - Cause: error in opening zip file

I'm using Android studio 0.5.2.

Can someone point me in the right direction on how to solve this?

Gospodin answered 23/5, 2014 at 11:31 Comment(3)
Try deleting the .gradle folders in both your home directory and your project's directory.Carob
@ScottBarta deleting .gradle folder from my user's directory and then clicking 'Sync Project with Gradle files' solved it for me. if you'll write it as an answer i'll mark it as accepted. Thanks :)Gospodin
@ScottBarta can you tell me where the .gradle folder exists. sorry i am very new in androidDorso
C
76

An "error in opening zip file" tends to mean that a file that Gradle has downloaded has somehow become corrupted -- this might be the download of Gradle itself (which the wrapper does), or a dependency that Gradle has downloaded to run your build.

Gradle doesn't attempt to detect or resolve the problem, so you need to fix it manually. The solution is often to purge Gradle's download caches and let it get fresh copies of what it needs. To do that, delete the .gradle directories in both your home directory and in your project's root directory and try building again.

Carob answered 23/5, 2014 at 23:25 Comment(5)
Thanks Scott for your answer., it helped my day. Was struggling to setup AS since Yes'day as there were issues with ADT23.0 with Eclipse and lost almost 2days of efforts. Decided to move to AS and now it's up and running. Let me begin the show there...Concavoconvex
@scott I have 2 projects with the same gradle version but only one of them suddenly is giving me the same errors. I did everything you said but the error is still there. FYI this project has implemented volley if that matters. Could you please help?Magnific
Note That: there are 2 .gradle folder we need to delete , one is in project directory other one is at C:/Users/Your Name/.gradle , i missed that hope it helps someoneMccreery
@Scott Barta can you tell me where the .gradle folder exists. sorry i am very new in android...Dorso
I ran into a project which uses git-lfs which was not setup on my machine, every time I did a build the .gradle cache would be corruptedAmaral
I
26

If you have limited internet plan then use the following method.

Step1: Close android studio

Step2: Go to C:\Users\Khurshid\.gradle\wrapper\dists\gradle-1.12-all\2apkk7d25miauqf1pdjp1bm0uo (if you want to configure gradle 1.12)

Step3: try to open the gradle-1.12-all.zip by double clicking it. If it gives error message then delete the zip file.

step4: go to https://services.gradle.org/distributions and download gradle-1.12-all.zip (54mb approx) and copy the same to the folder where you have previously deleted the zip file.

step5: open android studio and go to file->setting select 'gradle' and click on 'use local gradle distribution' and set 'gradle home' to 'C:\Users\Khurshid\.gradle\wrapper\dists\gradle-1.12-all\2apkk7d25miauqf1pdjp1bm0uo\gradle-1.12-all.zip' and click ok.

step6: It will download some file over the internet. If download doesn't start automatically then restart android studio.

step7: Be patience and let it download some important stuff and after that everything should be working fine. This method will help you save your internet data. Downloading the entire gradle directory will consume double the data.

Insignificancy answered 8/7, 2015 at 10:30 Comment(0)
E
5

I also faced the similar issue when imported the existing project into Android Studio, this might happened because of gradle version mismatch between two different Android Studio platform.

Solution(on Mac OS):

  1. Close the Android Studio.
  2. Locate the .gradle folder at User/.gradle/
  3. Delete the folder & clear the Trash.
  4. Relaunch the Android Studio & Sync your project. It will re-download the gradle plugins & configurations.
Erfert answered 19/4, 2017 at 7:54 Comment(0)
D
2

For me the solution to this error was to change the gradle wrapper version in ../gradle/wraper/gradle-wrapper.properties to a different/newer version.. I used:

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

Then call:

./gradlew --refresh-dependencies

This tells the wrapper to point to a new version and re-download all required dependencies. I suspect the error for me was caused by an interrupted download when first building the relevant project.

Diabolism answered 26/1, 2017 at 19:1 Comment(0)
V
0

I fixed this issue by...

  • Going to Settings... > Gradle
  • Selecting "Use local Gradle distribution."
  • Pointed it to my Gradle zip file: home/kersting/.gradle/wrapper/dists/gradle-1.12-all/6vpvhqu0efs1fqmqr2decq1v12/gradle-1.12

It should be something similar for you if you downloaded Gradle which you should have when you downloaded Android Studio. Be careful, the .gradle file may be hidden. I found it through the terminal, but "ls" didn't reveal it.

Vivianne answered 28/1, 2015 at 1:57 Comment(0)
L
0

I had the same problem, happened after turning on and off jack and jill tool chain. I tried removing .gradle but it didn't help. Removing the build directory inside my project folder resolves the problem.

Try this before removing .gradle as it will need near 200MB worth of download.

Leu answered 21/4, 2015 at 9:52 Comment(0)
P
0

I fixed the same issue via the following:

Go to File -> Settings -> Gradle

Input the following in the "Gradle VM options:" box: -XX:MaxHeapSize=256m -Xmx256m

Hit apply and Android Studio should build your project successfully.

Pisciculture answered 14/6, 2015 at 10:13 Comment(0)
S
0

Clearing .gradle directory didn't help, but clearing build directory did the job for me.

Steeplebush answered 18/1, 2016 at 17:3 Comment(0)
T
0

You just have to edit build.gradle file.

you should set the classpath to the latest gradle version

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

and Sync the project. All errors will be gone. What you can do is, make new project in android studio, which will have classpath of latest gradle and paste it into your project that having Cause: error in opening zip file. this error.

Triptolemus answered 2/3, 2016 at 21:45 Comment(0)
J
0

I had the same problem so and to fix it i download the last version of gradle:

https://services.gradle.org/distributions

and open the gradle in the right bar then choose gradle parameters and change the path of the old gradle into the new one.

Johnsson answered 22/3, 2017 at 12:3 Comment(0)
S
0

Deleting the .gradle folder worked for me. Problem resolved after I deleted .gradle folder

Snowflake answered 15/4, 2017 at 19:7 Comment(0)
O
0

One of the causes of this problem (since late 2019) is the decommissioning of HTTP services by Gradle - and I see you are using HTTP protocol in your distributionUrl. This means that if your [PROJECT_PATH]/gradle/wrapper/gradle-wrapper.properties file has an entry like:

distributionUrl=http\://services.gradle.org/distributions/gradle-{version}.zip

... then this entry will try to retrieve a ZIP file from a service no longer servicing it (http based one) and it will silently return an empty ZIP file; which consequentially will be the source of an error from any process trying to unzip that empty ZIP file.

To fix this, just change your [PROJECT_PATH]/gradle/wrapper/gradle-wrapper.properties file to have its distributionUrl entry to use https:

distributionUrl=https\://services.gradle.org/distributions/gradle-{version}.zip

Hope this helps.

Oink answered 8/12, 2019 at 7:47 Comment(0)
T
0

Simply change distributionUrl to latest like this:

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

It will download all necessary gradle files and your good to go.

Tephrite answered 31/1, 2020 at 12:25 Comment(0)
C
-1

In recent versions of Android Studio File -> Invalidate Caches / Restart is worth trying.

Combine answered 26/5, 2017 at 10:39 Comment(0)
B
-1

I had the same issue

  • Go to C:\Users\Jesus Navas.gradle\wrapper\dists\gradle-3.3-all(your gradle version).

  • Erase your current gradle version and write again in cmd "ionic build android".

  • However, your gradle will download again, then it will unzip it automatically, ready checkout the output .apk,

this solved my issue

B answered 13/8, 2017 at 2:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.