Gradle build fails with java.util.zip.ZipException: zip END header not found
Caused by: java.util.zip.ZipException: zip END header not foundShort answer
Java tried to open a file as a zip archive and found no zip ending, so the file is cut short or is not a zip. In Gradle that is a broken download in the user home: either the wrapper distribution or a cached library. Read the stack trace for the file name, delete only that item, and rebuild.
Fix it fast
1Find out which cause you have
Run the build with a full stack trace and find the path of the file that fails to open, just above the ZipException line. If the path contains wrapper/dists the wrapper download is bad; if it contains caches it is a cached library.
cd android && ./gradlew assembleDebug --stacktrace2Match what you see, then jump to its fix
- 1
The failing path is under .gradle/wrapper/dists, or the error appears right after the first download of GradleThe Gradle distribution in the wrapper folder is incompleteFix - 2
The failing path is under .gradle/caches, usually modules-2, and names a .jar, .aar or .zipA library file in the dependency cache was cut off while downloadingFix - 3
You deleted caches, but the same path is reported againThe Gradle user home is not the folder you cleanedFix
- 1
What does the error look like?
Caused by: java.util.zip.ZipException: zip END header not found
Cause 1 of 3
The Gradle distribution in the wrapper folder is incomplete
1Check
Gradle's wrapper downloads the zip named by distributionUrl in gradle/wrapper/gradle-wrapper.properties and stores it under the wrapper folder in the Gradle user home. Gradle reuses that stored copy on later runs, so a broken one keeps failing until it is removed.
cat android/gradle/wrapper/gradle-wrapper.properties
ls ~/.gradle/wrapper/dists2Fix
Delete the folder of the failing Gradle version under wrapper/dists. The wrapper downloads it again on the next run.
rm -rf ~/.gradle/wrapper/dists/gradle-<version>-bin3Verify
The next build downloads the distribution once and completes.
cd android && ./gradlew --versionConfirmed by docs.gradle.org
Cause 2 of 3
A library file in the dependency cache was cut off while downloading
1Check
Gradle keeps downloaded modules in caches under the user home, for example caches/modules-2. If a download dies halfway, the damaged file stays in that cache.
ls ~/.gradle/caches2Fix
Remove the module cache and let Gradle fetch the libraries again; it will download everything it needs on the next build.
rm -rf ~/.gradle/caches/modules-2
cd android && ./gradlew assembleDebug --refresh-dependencies3Verify
The build resolves its dependencies again and the exception does not return.
cd android && ./gradlew assembleDebugConfirmed by docs.gradle.org
Cause 3 of 3
The Gradle user home is not the folder you cleaned
1Check
The user home defaults to ~/.gradle and can be moved with the GRADLE_USER_HOME environment variable. A CI machine or an IDE setting may point somewhere else.
echo "$GRADLE_USER_HOME"
ls -d ~/.gradle2Fix
Clean the folder that the stack trace names, which is the one actually in use, instead of the default.
rm -rf "${GRADLE_USER_HOME:-$HOME/.gradle}/wrapper/dists/gradle-<version>-bin"3Verify
The run uses the freshly downloaded copy.
cd android && ./gradlew --versionConfirmed by docs.gradle.org
How do I stop it coming back?
- Let the first Gradle download finish on a stable connection, and do not kill the build while it runs.
- Set distributionSha256Sum in gradle-wrapper.properties so a wrong download fails the build at the first fetch.
- Do not delete or move the Gradle user home while a build is running.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Flutter release build cannot open the keystore: HmacPBESHA256 not available
Algorithm HmacPBESHA256 not available
The keystore is a PKCS12 file protected by a newer algorithm than the Java that is reading it understands.
3 causes, each with a fixMobile apps
Flutter Android build fails: Java is too new for this Gradle version
Unsupported class file major version 61
Gradle only runs on Java versions it knows.
3 causes, each with a fixMobile apps
Flutter Android: Failed to load FirebaseOptions from resource
Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.
On Android, Firebase reads its settings from a values.xml file that the Google services Gradle plugin builds from google-services.json.
4 causes, each with a fixMobile apps
Flutter Android build stops with Execution failed for task ':app:…'
Execution failed for task ':app:compileFlutterBuildRelease'.
The line only tells you which Gradle step broke; the task name in the quotes tells you why.
5 causes, each with a fixMobile apps
Flutter's Android build stops: JAVA_HOME is not set
ERROR: JAVA_HOME is set to an invalid directory
The Gradle wrapper script needs a Java runtime and looks in two places: the JAVA_HOME variable, then a java command on PATH.
3 causes, each with a fixMobile apps
flutter_local_notifications crashes on Android with Integer.intValue() on a null object reference
NullPointerException in setSmallIcon
The crash comes from the small icon.
2 causes, each with a fix