I updated android studio 2.3 and there is a bug, gradle doesn't build and it keeps giving me the same error for all projects.
Error:Failed to open zip file.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
Re-download dependencies and sync project (requires network)
I have already searched for a solution, but have not found any. I tried:
Invalidate Caches / Restart...
but nothing has changed.
Repair Gradle Installation
This usually happens when something goes wrong in Android Studio's first launch (eg. system crash, connection loss or whatever).
To resolve this issue close Android Studio and delete the following directory's content, necessary files will be downloaded on IDE's next launch.
macOS: ~/.gradle/wrapper/dists
Linux: ~/.gradle/wrapper/dists
Windows: C:\Users\your-username\.gradle\wrapper\dists
While downloading Gradle manually works, I recommend letting Android Studio do the work for you.
UPDATE 17 JULY 2018:
Even if the following solution still works as of today,I've found (thanks to the answer posted by Hamid Asghari and to the comment posted by Mahendra Dabi) that simply deleting the gradle dist directory and performing a reboot of the ide, will fix the issue (please read Hamid post for a full answer, and remember that OSX and Linux have the same gradle path).
If you still want to follow my original solution, you should at least consider using a more up-to-date version of Gradle (direct link of the gradle distribution repo: https://services.gradle.org/distributions/)
Original answer (dated 7 March 2017):
I've faced the same issue this morning after upgrading Android Studio to 2.3.
To solve the issue:
1) Manually download Gradle 3.3 binary (direct link: https://services.gradle.org/distributions/gradle-3.3-bin.zip)
2) Open your android studio root directory, and extract the zip to the gradle folder (for example in my Debian machine the full path is /opt/android-studio/gradle/gradle-3.3)
3) Open Android Studio, go to File->Settings->Build, Exectution, Deployment->Gradle and set "Gradle home" to point your new gradle-3.3 folder.
4) Sync and you are ready to go!
I faced the same issue 2 days ago and today I was able to solve it like this:
Go to this path C:\Users\user_name\.gradle\wrapper\dists where user_name is your username if its you own PC or your company's name.
Delete the latest gradle-****-all files since your latest update of android studio (ex. 2.3 or another version).
If your android studio is open, close it then reopen it. A newer Gradle version will be downloaded, it will take time depending on your internet speed, the download size is around 150-200 MB before extraction so if android studio takes a long time to refresh just know its downloading. (To check the download progress right click on the new gradle folder, go to properties and check the size).
Find 'gradle-wrapper.properties' in root project
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Change "https" to "http".
There are Following Steps to solve this issue.
1. Go to C:\Users\ ~User Name~ \.gradle\wrapper\dists.
2. Delete all the files and folders from dists folder.
3. If Android Studio is Opened then Close any opened project and Reopen the project. The Android Studio Will automatic download all the required files.
(The required time is as per your Internet Speed (Download Size will be about "89 MB"). To see the progress of the downloading Go to C:\Users\ ~User Name~ \.gradle\wrapper\dists folder and check the size of the folder.)
just remove and reDownload wrapper gradle.
Mac Home/.gradle/wrapper/dists/
remove gradle version and sync gradle in project and run project.
Go to Project pane> Android > Gradle Scripts and open "graddle-wrapper.properties" file check the distribution URL:
Go to your ".gradle/wrapper/dists/" folder and remove that file for me it was "gradle-5.6.4-all"
Then go back to android studio and click on File > Sync Project with Gradle Files. And it will start to download again
****Following solution is working for me****
Manually deleted all files from C:\Users\Admin.gradle\wrapper\dists\
where Admin is my user name
Android Studio 4.1.1 has this bug,
In gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
This won't download and always gives 'gradle cache corrupt' error, but a small change makes it work fine
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Now sync the gradle again and it's done.
1.Go to "/Users/****/.gradle/wrapper/dists/gradle-.-all/*****".
2.Delete the "gradle-.-all.zip.lck" file.
3.Invalidate Cache and Restart.
you do not need to clean all files in dir
C:\Users\ ~User Name~ \.gradle\wrapper\dists.
and download all of them again
instead you can just delete the folder of gradle version you failed to download. In my case it was gradle-4.4-all so i just deleted that folder and android studio re downloaded gradle-4.4-all for me
In case you don't know version you was downloading:
Just go to help menu > show logs in explorer
their you will find idea.log open it and search for
Could not install Gradle distribution from 'https://services.gradle.org/distribution`
once you find it you will find gradle version you failed to download
This was the best solution for me, just follow this path C:\Users\yourusername.gradle\wrapper\dists then delete all the files inside this folder. Close your android studio and restart it and it will automatically download the updated gradle files.
I was upgrading gradle from 4.1 to 4.10 and my internet connection timed out.
So I fixed this issue by deleting "gradle-4.10-all" folder in .gradle/wrapper/dists
Taking a cue from #Mikel Yang, I found out that instead of deleting the ~/.gradle/wrapper/dists/ folder (which will means downloading the gradle files for different apps on my Android Studio), I decided to change the gradle.wrapper.properties file to any latest gradle --all.zip. So
Find 'gradle-wrapper.properties' in root project
distributionUrl=https\://services.gradle.org/distributions/gradle-{lastest}-all.zip
this way l get to save some data and time.
This happened to me because of a partially downloaded gradle distribution zip
To resolve simply go to below path
"C:/Users/your_username/.gradle"
OR
pull your gradle path from
File->Settings->Build, Exectution, Deployment-> Gradle -> gradle service directory path.
Delete the partially downloaded distribution gradle folder
Go to Studio (no need to restart) and perform gradle sync
Go to "File" in android studio, Click "invalidate caches/Restart" and "Invalidate and Restart"
That also works
I faced the issue, In my understanding, It is because of invalid combination of Android Studio And Gradle Plugin versions. I was using Gradle version 5.4.1 and Studio version 3.4, hence I updated the Android studio to 3.5 and the issue got resolved
You can delete the latest gradle-.-all folder from the below path
Windows: C:\Users\your-username.gradle\wrapper\dists
find file gradle-wrapper.properties
update with :
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
1). Android studio-> file-> "Invalidate Caches/Restart" -> "Invalidate and Restart"
wait for gradle sync
2). Download gradle.x.x.x-bin.zip using browser
unzip it and place it in ".gradle/wrapper/dists/gradle-x.x.x-bin\xxxxxxxxxxx(auto generated folder)/
then restart android studio
I'm trying to build Terminal Emulator for Android. I'm running Android Studio 1.4 in Kubuntu 15.04. I also tried building it in Ubuntu 14.04 LTS with the same results. The project requires the latest Android NDK, SDK 22, and SDK 11 which I've downloaded and configured in Android Studio. My system gradle version is 2.8, and Android Studio has downloaded some other versions internally. I'm using jdk1.8.0_65, which is set to JAVA_HOME and configured in Android Studio. I've built several other projects with my configured Android Studio and only seem to have a problem with this project. I need to use this project as a base for an app I'm developing.
I end up with same error, posted below, no matter what route I take to fix it in Android Studio. This is generally what I've done to try and get the project to work. I open up the project unmodified in Android Studio. I click Build >> Rebuild Project. I get an error telling me ndk implementation is deprecated. I add a file gradle.properties to the root directory of the project with the line android.useDeprecatedNdk=true and rebuild. It gives me an error: Task 'generateDebugTestSources' not found in project. I execute Sync Project With Gradle Files to resolve it. Then I end up with the following error and can't get past it.
Gradle 'Android-Terminal-Emulator-master' project refresh failed
Error:exception during working with external system:
or
Gradle sync failed: exception during working with external system:
Consult IDE log for more details (Help | Show Log)
idea.log
Things I've done to try and get the project to build:
Modify all of the project's build.gradle files to use the experimental plugin
Use different versions of Android Studio
Switch from openjdk to Oracle's jdk
Upgrade gradle to the latest version
Set gradle to default wrapper (default) and also set gradle to different versions
invalidate cache, remove ~/.gradle, and rebuild project
Make sure PATH includes the gradle and jdk bin directories and is in ~/.bashrc, ~/.profile, and ~/.zshrc
remove proguard from libtermexec library
reboot computer
I should note that the project builds without issue on the command line. I'd really like to get the project to build in Android Studio for development.
Install Arch and run Android Studio there.
I decided to try building Terminal Emulator on my Arch server, so I installed a xfce (Desktop Environment) and Android-Studio through pacman. I followed the same general path to get things setup, and the app built without issue.
The idea log Android Studio generated for the failed build on Windows and Ubuntu didn't point to any clear problem, even with --stacktrace enabled with gradle. I'm not going to waste my time figuring out why gradle doesn't want to build apps in Ubuntu or Windows.
When i have move my project to my laptop and import it in file/import project, Android studio alert me
project refresh failed
Error: The device is not ready
Look inside your gradle file for lines something like this (this is mine):
maven {
url "D:/Android/sdk/extras/android/m2repository"
}
I do not have drive D:\ with Android SDK on my new laptop. That is why I met the error:
Gradle sync failed: The device is not ready
Consult IDE log for more details (Help | Show Log)
In the Android Studio's log I found the line:
Caused by: org.gradle.api.UncheckedIOException: Could not normalize path for file 'D:\Android\sdk\extras\android\m2repository'.
Hope this post will help other people to handle this error quickly.
try this algorythm:
File -> Invalidate caches / Restart
Shutdown Android Studio
Rename/remove .gradle folder in the user home directory
Restart Android Studio let it download all the Gradle stuff it needs
Gradle build success
Rebuild your project
You should connect your android device to computer
i think you have driver problem .and you should install your device driver
if you use windows bellows link show you how to install driver
Manually installing Android ADB USB Driver
If you have implemented product flavors in a project then please check implementation and keystore path. In my case it was the reason and i have corrected keystore file path in gradle it is working fine now.
I had system environment variables GRADLE_HOME and GRADLE_USER_HOME set to non existings directory, which I had to remove to fix a similar issue.
I have downloaded android studio and sdk and everything required but when I start a new project studio starts downloading gradle which is already downloaded with android studio. If I try to stop that download, it can't be stopped, I need to shutdown my laptop.
Please tell me why this happens!
And if I import any project then it shows a message that gradle build failed and tells me to install build tools API Level 7 which NOBODY uses now a days. What's wrong with this studio??
I am using Ubuntu 14.04, .gradle directory of my home folder has files of more than 300 Mb I don't understand what this android studio keeps downloading.
Please help me fixing this problem
That is normal one time download of maven gradle dependencies and packages. However it usually takes a long time to download and build. Not sure what are the reasons for this.
Android studio contains gradle essentials, but for some reasons that is insufficient to run command line tools.
There is a workaround to skip this download by adding gradle repo directory to android studio settings (Configure --> Settings --> Gradle). You have to manually add GRADLE_HOME to the system PATH variable according to your operating system. Run gradle-v in command line to confirm everything works right.
Just updated Android-Studio to version 0.2.7 an now I get the error message from the title:
In the log window there is link to the grade setup:
No matter which option I use the error message stays the same.
I deleted my ~/.gradle directory and projects **/.gradle directories.
It seems that nothing helps.
Nitpick: compile on the command-line using \opt\gradle\1.6\bin\gradle.bat build works fine.
Go to Preferences > Project Settings > Gradle and choose "Use gradle wrapper" instead of the bundled option
Open your gradle-wrapper.properties and change the distributionUrl to use 1.7 if it is not already (mine was 1.6), i.e. distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip
I managed to fix my project through some combination of invalidating Android Studio cache, deleting .idea and .gradle directories and .iml files, restarting Studio, and reimporting the project:
on Mac OSX using Homebrew, brew install gradle then pick local gradle distribution and point to /usr/local/Cellar/gradle/1.7/libexec for gradle home:
You do not want to manage gradle at a system level, it is better handled per project. Android Studio projects already setup gradle wrapper handling when creating new projects but if you have an older one you can add the same file that Android Studio does. Think of this as an gradle bootstrap file that will download the correct gradle version per project. You can also read up on Gradle Wrapper and generate a shell script called gradlew that will provide gradle-free bootstrapping.
In gradle/wrapper/gradle-wrapper.properties in your project directory make sure you have:
#
#Tue Oct 08 13:40:54 CEST 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip
Then when you go into Gradle you can set it to use the gradle wrapper. This is the default when creating new projects in Android Studio.
There are at least three approaches to migration or adding Gradle properly and using the new project structure Google and Android Studio has introduced.
Create a new project and copy over the code
Export from Eclipse to Gradle (deprecated)
Import code into Android Studio (recommended)
Try to manually get everything in order by creating the correct gradle files and reorganizing the project.
For now I'm copying the files over to a new project until the tools get a bit better.
We have two computers, one of which gave that same message after upgrading to Android Studio 0.2.7. We noticed that the computer which could still build had Gradle installed independently of Android Studio.
Installing Gradle 1.6 downloaded from the Gradle web site fixed this issue on the computer that wouldn't build.
My fix was basically what Abe did but I wanted to give a bit more explanation:
Download gradle 1.6 from the gradle website
Extract somewhere on your pc/mac
Open up android studio, go to Preferences -> Gradle (left panel) -> and chooose Local gradle distribution.
Point Gradle home to the location where you extracted gradle.
This fixed the issue for me. Using the gradle wrapper and the bundled gradle distribution both failed
In my case, i updated gradle to the latest version (1.8) and then changed the gradle.build files (for my project and for the libraries i was using) like these:
dependencies {
classpath 'com.android.tools.build:gradle:0.6.1+'
}
The Synchronize files and Refresh/Invalidate cache. This seems to solve the problem. I think that Gradle in order to determine the minimum required version just reads the above value.
Here's what I did to get my project working:
Installed Gradle 1.7 on my OS (OS X users can use brew for this)
Added this to my local.properties file: sdk.dir=/Applications/Android\ Studio.app/sdk
Created gradle wrappers with gradle wrapper command.
Chose "Use gradle wrapper (recommended)" option in Android Studio.