前几天打开Android Studio,弹出一个Update界面,没有看清楚我就点了Update,后来就出问题了,Make Project没有问题,一运行就会提示如下的错误。借此机会在这里记录一下,防止以后出现,也许可能会因此帮助到一些人,save your data and time~
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)
解决方法:
我花了好几天,试了网上的各种答案,不过似乎都不适合,我把这些答案贴在下面,大家也可以参考一下。我自己的解决方法是最后一个,可以先尝试我的解决方案再倒回来试其他的。
- 重新下载 Gradle 版本到Android Studio的安装目录
- Manually download Gradle (direct link: https://services.gradle.org/distributions/)
- 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)
- Open Android Studio, go to File->Settings->Build, Exectution, Deployment->Gradle and set “Gradle home” to point your new gradle-3.3 folder.
- Sync and you are ready to go!
- Repair Gradle Installation
- 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).
macOS下目录: ~/.gradle/wrapper/dists
Linux下目录: ~/.gradle/wrapper/dists
Windows下目录: C:\Users\your-username\.gradle\wrapper\dists
- 修改gradle-wrapper.properties
- Find ‘gradle-wrapper.properties’ in root project
distributionUrl=https://services.gradle.org/distributions/gradle-***-all.zip
- Change “https” to “http”.
- 修改bulid.gradle
- 打开工程下的第一个bulid.gradle(括号内是你的Project名)
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
- 将依赖项版本号修改成前一个版本(如3.3.1)或其他之前未出错的版本(一开始弹出的Update就是此dependencies升级)此时会弹出升级的窗口,请忽略它。
- 重新Make Project,运行到手机上,搞定!