Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova Build Gradle Error while opening/extracting zip file

When I Run: cordova build, I got this:

Running command:/Users/tyrant/workspace/ideaProject/hello/platforms/android/cordova/build
ANDROID_HOME=/Users/tyrant/software/android/android-sdk-macosx
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
Running:/Users/tyrant/workspace/ideaProject/hello/platforms/android/gradlew cdvBuildDebug -b   /Users/tyrant/workspace/ideaProject/hello/platforms/android/build.gradle    -Dorg.gradle.daemon=true
Deleting directory /Users/tyrant/.gradle/wrapper/dists/gradle-2.2.1-all/2m8005s69iu8v0oiejfej094b/gradle-2.2.1
Unzipping /Users/tyrant/.gradle/wrapper/dists/gradle-2.2.1-all/2m8005s69iu8v0oiejfej094b/gradle-2.2.1-all.zip to /Users/tyrant/.gradle/wrapper/dists/gradle-2.2.1-all/2m8005s69iu8v0oiejfej094b
Exception in thread "main" java.lang.RuntimeException: java.util.zip.ZipException: error in opening zip file
atorg.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:78)
at org.gradle.wrapper.Install.createDist(Install.java:47)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:215)
at java.util.zip.ZipFile.<init>(ZipFile.java:145)
at java.util.zip.ZipFile.<init>(ZipFile.java:159)
at org.gradle.wrapper.Install.unzip(Install.java:160)
at org.gradle.wrapper.Install.access$400(Install.java:29)
at org.gradle.wrapper.Install$1.call(Install.java:70)
at org.gradle.wrapper.Install$1.call(Install.java:47)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
... 3 more

/Users/tyrant/workspace/ideaProject/hello/platforms/android/cordova/node_modules/q/q.js:126
                throw e;
                      ^
Error code 1 for command:     /Users/tyrant/workspace/ideaProject/hello/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/tyrant/workspace/ideaProject/hello/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /Users/tyrant/workspace/ideaProject/hello/platforms/android/cordova/build: Command failed with exit code 1
You may not have the required environment or OS to build this project
Error: /Users/tyrant/workspace/ideaProject/hello/platforms/android/cordova/build: Command failed with exit code 1
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

How should I solve this problem?

like image 566
XBroder Avatar asked Sep 12 '15 06:09

XBroder


4 Answers

This is because you have already downloaded a corrupt version of the Gradle package in your system directory. (Maybe due to internet connection issues?) Just go to your local path below and remove all contents inside it.

/Users/tyrant/.gradle/wrapper/dists/gradle-2.2.1-all/2m8005s69iu8v0oiejfej094b/

Run cordova build again. This will fix your issue for sure.

like image 130
Nick Song Avatar answered Oct 22 '22 17:10

Nick Song


I read a lot of this problem, and i found 2 solutions, the 1st one is to remove all contents inside it (as the last post said) but it doesn't work for all, in my case don`t.

The other solution is to put in a local folder of the project the zip file and change the path, and that is not a real solution, cause the size is 50 mb...

So the easiest way i found is just download the right zip from the Gradle site--> https://services.gradle.org/distributions and just replace it in your computer manually... and this works instantly for me.

like image 39
Limitky Avatar answered Oct 22 '22 16:10

Limitky


Check whether you are having download limit and, if so, download the gradle zip file manually, place it in folder such as /Users/tyrant/.gradle/wrapper/dists/gradle-2.2.1-all/2m8005s69iu8v0oiejfej094b/ and run the command.

like image 44
Ajitesh Avatar answered Oct 22 '22 16:10

Ajitesh


For anyone facing this problem when first building a react-native Android app, it's likely to be the gradle-2.4 file, which is generally found in:

/var/root/.gradle/wrapper/dists/gradle-2.4-all/<some_string>/gradle-2.4

Just manually delete the zip file, download a new copy and replace.

like image 25
J. Rosenbaud Avatar answered Oct 22 '22 15:10

J. Rosenbaud