Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle build fails with java.util.zip.ZipException: zip END header not found

ErrorCaused by: java.util.zip.ZipException: zip END header not found

Short 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.

  • Applies to Gradle 8.x and 9.x wrapper, Android Gradle Plugin 8.x, Flutter 3.3x stable, Java 17 and 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 --stacktrace
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The 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. 3You deleted caches, but the same path is reported againThe Gradle user home is not the folder you cleanedFix

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/dists

2Fix

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>-bin

3Verify

The next build downloads the distribution once and completes.

cd android && ./gradlew --version

Confirmed by docs.gradle.org

Did this fix it?

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/caches

2Fix

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-dependencies

3Verify

The build resolves its dependencies again and the exception does not return.

cd android && ./gradlew assembleDebug

Confirmed by docs.gradle.org

Did this fix it?

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 ~/.gradle

2Fix

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 --version

Confirmed by docs.gradle.org

Did this fix it?

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:

Related fixes

Mobile 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 fix

Mobile 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.