Exception in thread "main" java.util.zip.ZipException: zip END header not found
at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1474)
at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1482)
at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1320)
at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1282)
at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:709)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:243)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:172)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:186)
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
This exception error is showing when the Flutter application is running.
2
Answers
The Gradle task assembleDebug failed with exit code 1 error in Flutter can occur due to various reasons such as issues with AndroidX compatibility, incorrect Gradle version, network problems, or corrupted Gradle files. Here are several approaches to resolve the issue:
Ensure AndroidX Compatibility: If your project uses Firebase plugins
that require AndroidX, ensure your project is migrated to AndroidX.
Update gradle.properties with the following lines:
android.useAndroidX=true
android.enableJetifier=true
Then, refactor your project to AndroidX through Android Studio
Upgrade Flutter Packages: Sometimes, simply upgrading the Flutter
packages can solve the problem. Run:
flutter pub upgrade
Update Gradle Version: Check the gradle-wrapper.properties file and
ensure the distribution URL points to the correct Gradle version.
Also, verify that the build.gradle file specifies the correct Gradle
plugin version
Clean Project and Clear Cache: Delete .gradle and .m2 directories
from your home directory and within your project. Then, run the
following commands:
flutter doctor
flutter clean
flutter packages pub cache clean
Check Network Conditions: Ensure you have a stable internet
connection since Gradle needs to download dependencies during the
build process
Avoid Special Characters in Path: If your project path contains
special characters, it may cause issues. Move your project to a path
without special characters.
Correct Android Home Path: Ensure that the ANDROID_HOME environment
variable is set correctly on Windows. An incorrect path can lead to
build failures.
Review Verbose Logs: Run flutter run –verbose to get detailed logs
that can help identify the specific cause of the failure.
Invalidate Caches in Android Studio: Go to File > Invalidate Caches
/ Restart… in Android Studio to clear the IDE’s internal cache,
which might be causing issues.
Try these solutions one by one, checking if the error is resolved after each step. If none of these solutions works, consider providing the verbose logs (flutter run –verbose) for further analysis.
The error you’re encountering seems to be related to an issue with Gradle’s dependency resolution or corruption of the Gradle wrapper’s distribution file.
upgrade flutter