I am getting a java.util.zip.ZipException while preparing my NativeScript project for Android (tns prepare android):
Failed to build plugin nativescript-barcodescanner :
Error: Command ./gradlew failed with exit code 1 Error output:
Exception in thread "main" java.util.zip.ZipException: zip END header not found
This error seems to be occurring only when certain plugins (nativescript-barcodescanner and nativescript-socket.io) are installed. If I try to build without those plugins, the build works properly. So it's probably not a problem with Gradle itself (as in e.g.this answer).
First occurrence
I first encountered the problem with nativescript-barcodescanner after upgrading NativeScript from version 3.2.0 to 4.2.4 and subsequently updating my project packages as well. Everything was working fine before the upgrade.
However, the problem is not specific to my project. If I create a new project and add nativescript-barcodescanner
$ tns create testproject && cd testproject
$ tns plugin add nativescript-barcodescanner
$ tns prepare android
...then the error shows up again. When I tns remove nativescript-barcodescanner, the build runs properly.
Steps taken
At first, I thought it was a problem with the nativescript-barcodescanner plugin (here is my GitHub issue). However, I now ran into the same error with a NativeScript-Vue template, where the build failed at nativescript-socket.io.
I have tried the following steps, without success:
- Deleting
node_modulesand re-runningnpm install - Clearing the npm cache (
~/.npm/_cacache) and re-downloading all dependencies - Creating a fresh NativeScript project (problem comes back when I
tns addthe plugin) - Removing the plugin and installing an older version
- Re-installing NativeScript (
npm i -g nativescript) - Deleting the Gradle cache folder (
~/.gradle/caches) and retrying the build - Using a newer version of java (OpenJDK 11 instead of 8)
My (current) guess is that some file that has been incorrectly downloaded. This is quite likely because my Internet connection is not very great and might have disconnected in the middle. However, I can't make out which file is causing trouble (I'd rather not re-download the whole setup).
Full output
Here is my NativeScript setup info:
$ tns info
✔ Getting NativeScript components versions information...
✔ Component nativescript has 4.2.4 version and is up to date.
✔ Component tns-core-modules has 4.2.1 version and is up to date.
✔ Component tns-android has 4.2.0 version and is up to date.
✔ Component tns-ios has 4.2.0 version and is up to date.
And this is a sample run (this was with OpenJDK 8 so it says error opening zip file instead of the more detailed zip END header not found):
$ tns create bartest
npm notice created a lockfile as package-lock.json. You should commit this file.
added 3 packages in 295.509s
Project bartest was successfully created.
$ cd bartest
$ tns plugin add nativescript-barcodescanner
+ nativescript-barcodescanner@2.7.8
added 1 package in 97.781s
Successfully installed plugin nativescript-barcodescanner.
$ tns prepare android
Copying template files...
Platform android successfully added. v4.2.0
Preparing project...
Successfully prepared plugin nativescript-barcodescanner for android.
Successfully prepared plugin nativescript-theme-core for android.
Successfully prepared plugin tns-core-modules for android.
Successfully prepared plugin tns-core-modules-widgets for android.
Failed to build plugin nativescript-barcodescanner :
Error: Command ./gradlew 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)
Is there any way to figure out which zip file is causing the error, or other way I can try to debug this problem?