1

I get such error while run a project in flutter. Why is this happening and how can I fix this error?

Exception in thread "main" java.util.zip.ZipException: zip END header not found
    at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1581)
    at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1476)
    at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1483)
    at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1288)
    at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1251)
    at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:732)
    at java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:849)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:247)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:177)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:191)
    at org.gradle.wrapper.Install.unzip(Install.java:214)
    at org.gradle.wrapper.Install.access$600(Install.java:27)
    at org.gradle.wrapper.Install$1.call(Install.java:74)
    at org.gradle.wrapper.Install$1.call(Install.java:48)
    at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
    at org.gradle.wrapper.Install.createDist(Install.java:48)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Exception: Gradle task assembleDebug failed with exit code 1

5 Answers 5

13

Why is this happening?

=> The error is related to Gradle, it is usually caused by a corrupt or incomplete Gradle setup

how to fix this error?

For mac user: open terminal and execute

cd ~

rm -rf .gradle

For windows user:

Go to the root directory C:\Users\YourUser and locate the hidden .gradle folder and delete it. and then run your app connected to an Android emulator or device, don't cancel and make have a stable internet connection, this will download fresh Gradle

Sign up to request clarification or add additional context in comments.

2 Comments

rm: .gradle: Permission denied
Try using sudo along with the command.
0
defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.ducafecat.woo_commerce.flutter_woo_commerce_getx_learn"
    // You can update the following values to match your application needs. 
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
    // minSdkVersion flutter.minSdkVersion
    minSdkVersion 21
    // targetSdkVersion flutter.targetSdkVersion
    targetSdkVersion 33   // change this 31 to 33
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

Comments

0

I have a similar issue using Flutter

    Execution failed for task ':flutter_inappwebview:minifyReleaseWithR8'.
[        ] > java.util.zip.ZipException: zip END header not found

For some reasons this only happens when building a release but generating a debug apk works fine.

I tried everything about downloading gradle manually nothing works. Flutter suggests this fix:

[!] The shrinker may have failed to optimize the Java bytecode.            │ To disable the shrinker, pass the `--no-shrink` flag to this command.       To learn more, see: https://developer.android.com/studio/build/shrink-code 

However, when I compile with --no-shrink it seems that the directive is being ignored.

I have this in my build.gradle

buildTypes {
        release {
            shrinkResources false
            minifyEnabled false
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

Any suggestions will greatly help

Comments

0

I've faced same issue and in my case I had firstly open an android folder

android>gradel>wrapper>gradle-wrapper.properties

in gradle-wrapper.properties change

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

to

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip

And then invalid caches and restarted fixed my issue

1 Comment

and then after invalid cache and restart
-1

Had a similar issue. What I did was I headed to my gradle-wrapper

android>gradle>wrapper>gradle-wrapper.properties

copied the link and pasted in my browser and directly downloaded the file.

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip

After download I pasted the zip file in the


C:\Users\USER\.gradle\wrapper\dists\gradle-7.6.3-all\aocdy2d2z8kodnny3rsumj8i8

If you ran the build command, then I believe there should be a folder created for that wrapper in the .gradle, so just locate the folder depending on your gradle version and paste the zip.

The issue occurs when I change the gradle wrapper in my app. This method is what I use to solve it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.