Cant run or build apk due to unzipping gradle


#1

I have installed android studio with necessary packages, but when i tried to build apk with ionic cordova build android it cant work, these are the messages:

> [12:35:04]  lint finished in 6.13 s
> ANDROID_HOME=C:\Users\Gilles\AppData\Local\Android\sdk
> JAVA_HOME=C:\Program Files\java\jdk1.8.0_171
> studio
> Subproject Path: CordovaLib
> Subproject Path: app
> Unzipping C:\Users\Gilles\.gradle\wrapper\dists\gradle-4.1-all\bzyivzo6n839fup2jbap0tjew\gradle-4.1-all.zip to C:\Users\Gilles\.gradle\wrapper\dists\gradle-4.1-all\bzyivzo6n839fup2jbap0tjew
> 
> Exception in thread "main"
> 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:225)
>         at java.util.zip.ZipFile.<init>(ZipFile.java:155)
>         at java.util.zip.ZipFile.<init>(ZipFile.java:169)
>         at org.gradle.wrapper.Install.unzip(Install.java:215)
>         at org.gradle.wrapper.Install.access$600(Install.java:27)
>         at org.gradle.wrapper.Install$1.call(Install.java:75)
>         at org.gradle.wrapper.Install$1.call(Install.java:48)
>         at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
>         at org.gradle.wrapper.Install.createDist(Install.java:48)
>         at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
>         at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
> (node:21156) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with exit code 1 Error output:
> Exception in thread "main" 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:225)
>         at java.util.zip.ZipFile.<init>(ZipFile.java:155)
>         at java.util.zip.ZipFile.<init>(ZipFile.java:169)
>         at org.gradle.wrapper.Install.unzip(Install.java:215)
>         at org.gradle.wrapper.Install.access$600(Install.java:27)
>         at org.gradle.wrapper.Install$1.call(Install.java:75)
>         at org.gradle.wrapper.Install$1.call(Install.java:48)
>         at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
>         at org.gradle.wrapper.Install.createDist(Install.java:48)
>         at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
>         at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
>     at ChildProcess.whenDone (C:\xampp\htdocs\afrifamemoboapp\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
>     at emitTwo (events.js:126:13)
>     at ChildProcess.emit (events.js:214:7)
>     at maybeClose (internal/child_process.js:925:16)
>     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
> (node:21156) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
> (node:21156) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

What can i do?


#2

This is due to the corrupted gradle, i fixed this by following these steps:

Step1: Close android studio

Step2: Go to C:\Users{username}.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{username}.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.