Sanket Vekariya
Sanket Vekariya

Reputation: 2956

Flutter: Exception in thread "main" java.util.zip.ZipException: error in opening zip file

I created a new flutter project in android studio 3.5, but facing error

Exception in thread "main" java.util.zip.ZipException: error in opening zip file

Efforts for the solution: this, this but did not work for me.

Upvotes: 17

Views: 44160

Answers (14)

Priya Sindkar
Priya Sindkar

Reputation: 515

For what it's still worth- For me, opening the Android project in Android Studio and deleting the gradle distribution zip and syncing the project again did the trick. As mentioned in several answers above, the error is due to corrupted gradle zip and re-syncing downloaded the full uncorrupted file again.

Upvotes: 0

vikas
vikas

Reputation: 330

I was facing the same issue, I added this in gradle-wrapper-properties, and it get resolved

  1. Go to your Flutter project folder,

  2. Go to android>gradle>wrapper

  3. Select gradle-wrapper-properties

  4. Paste the below URL.

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

If it does not work for you, you can check the other version https://services.gradle.org/distributions/

Upvotes: 0

Ralph Maruva
Ralph Maruva

Reputation: 83

Had the same issue, just restarted my machine. As simple as that.

Upvotes: -1

rahm_rny12
rahm_rny12

Reputation: 105

I got this error, and i check .gradle directory, it's have gradle with 6.7 version in the wrapper/dists but there is no file in the daemon folder. So i delete the file in the wrapper/dists and the gradle re-download it's self again.

Upvotes: 0

aamirsuhxil
aamirsuhxil

Reputation: 291

  1. Browse to the official Gradle Distributions webpage and check what is the latest version of gradle all.zip file, for example (at the time of writing) gradle-6.7-all.zip and copy the address

  2. Go to your Flutter project dropdown,

    drop down android>gradle>wrapper

  3. Select gradle-wrapper-properties

  4. Paste the URL you copied earlier. For example:

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

Upvotes: 29

K.Amanov
K.Amanov

Reputation: 1618

If your internet connection is not stable you can try manual setup: First, download the latest gradle...-all.zip from https://services.gradle.org/distributions/ and unzip it.

For now, the latest version is: https://services.gradle.org/distributions/gradle-7.3.1-all.zip

And, do steps described here:

  1. Open <path_to_flutter_app>/android/gradlew

  2. Find: CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar and replace with: CLASSPATH=<path_to_downloaded_gardle>/gradle-7.3.1/lib/gradle-launcher-4.6.jar

  3. Find: exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" and replace with: exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.launcher.GradleMain "$@"

  4. flutter run

Upvotes: 0

Try to change your distributionUrl to gradle-7.1-all.zip

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

enter image description here

Upvotes: 2

Sandeep Peddi
Sandeep Peddi

Reputation: 119

There must be error while downloading Graddle File. Check the following code in the gradle/wrapper/gradle-wrapper.properties graddle_wrapper_properties_rectified_image

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-7.1-all.zip //change 7.1 to latest version available in below website

In my case, there is an additional ':' after 'https' and the number was an older version, But correcting it worked for me. U can refer to the below website to know the latest available version of file type "all.zip" and Update the number or whole link properly and as it is around 150 MB. you need to have an active internet connection and wait for a while by pressing Run once. There is no need to worry until u see any red lines.

https://services.gradle.org/distributions/

Upvotes: 3

M.Adnan Ijaz
M.Adnan Ijaz

Reputation: 141

I solved it by going into android/gradle/gradle-wrapper.properties and paste these lines:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

Upvotes: 0

emma-ea
emma-ea

Reputation: 404

Error means there is an incomplete/corrupted gradle.*.zip file download. Locate gradle version used by your project in the gradle-wrapper.properties, version should be specified in the distributionUrl value.

Move into {user-home}/.gradle/wrapper/dists/{gradle-version}/{generated-folder}/* and delete all files in the folder.

Rerunning your project should download the gradle file

This happens when you have poor internet connection to download the needed gralde file to run your project. you can manually download from the gradle distribution site and place in folder to resolve issue.

Upvotes: 5

Ayoub Arroub
Ayoub Arroub

Reputation: 495

Select the adequate Gradle version from gradle distributions that go with your IDE.

For example, I have an android studio Built on 02-Dec-2020
the gradle-6.8-rc-2-all.zip 17-Dec-2020 work fine for me.

Upvotes: 0

oalshokri
oalshokri

Reputation: 51

I had the same problem. In my case, there was an additional slash in the distributionUrl property. I used this website https://services.gradle.org/distributions/ to get the latest distribution of gradle -all.zip. (You will get something like: https://services.gradle.org/distributions/gradle-6.7.1-all.zip)

Then, use it in gradle-wrapper.properties file like this:

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

Upvotes: 4

Nikhil
Nikhil

Reputation: 1043

Change distributionUrl in android->gradle->wrapper->gradle-wrapper.properties to distributionUrl=https://services.gradle.org/distributions/gradle-4.10.1-all.zip

Upvotes: 2

Sanket Vekariya
Sanket Vekariya

Reputation: 2956

After hours of effort, I came up with the solution.
I have changed gradle wrapper properties distribution url version to: 5.5.1-all which was available in my system.
Due to some reason, android studio was fetching the latest version which was not in my system.

Upvotes: 17

Related Questions