17

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.

Sanket Vekariya
  • 2,848
  • 3
  • 12
  • 34

14 Answers14

29
  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
    
CoderUni
  • 5,474
  • 7
  • 26
  • 58
aamirsuhxil
  • 291
  • 1
  • 3
  • 8
16

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.

Sanket Vekariya
  • 2,848
  • 3
  • 12
  • 34
4

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
h3t1
  • 1,126
  • 2
  • 18
  • 29
oalshokri
  • 51
  • 3
4

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.

emma-ea
  • 324
  • 2
  • 5
3

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/

2

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

1

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

Nikhil
  • 1,023
  • 17
  • 35
0

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.

Ayoub Arroub
  • 302
  • 2
  • 10
0

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
M.Adnan Ijaz
  • 91
  • 10
0

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

K.Amanov
  • 1,278
  • 14
  • 23
0

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.

rahm_rny12
  • 75
  • 8
0

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/

vikas
  • 295
  • 4
  • 16
0

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.

Priya Sindkar
  • 368
  • 3
  • 11
-1

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

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33154019) – Răzvan Puiu Nov 16 '22 at 08:52