Error:Failed to open zip file.Gradle's dependency cache may be corrupt 【Mac系统 AS】


转载请注明出处:http://blog.csdn.net/yudbl/article/details/78581508


To take advantage of all the latest features (such as Instant Run), improvements and security fixes, we strongly recommend that you update the Android Gradle plugin to version 3.0.0 and Gradle to version 4.1.  You can learn more about this version of the plugin from the release notes.



最近手“不听使唤”,AS提示更新就点啦,结果等了好久,因公司的网不敢恭维就断开了,后来重新开启项目工程时,出现如下提示:

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)


估计是文件没更新完或损坏的原因


实践解决方式:

方式1:

(1) AS项目中找到文件:build.gradle(Project: xx项目名)

把以前项目的classpath复制过来


(2)AS项目中找到文件:gradle-wrapper.properties

把以前项目的 distributionUrl复制过来




方式2:

因为我有强迫症,既然更新了,我就想用最新的版本,于是尝试成功了此种方式。

AS的菜单栏,点击Android Studio,Preferences, Grade




搜索找到Gradle,点击标注的图标【或 复制路径“/Users/luminal/.gradle”,回到桌面 command+shift +G搜索找到】




把目录下最近更新的gradle删除




AS项目中找到文件:gradle-wrapper.properties,

拷贝链接放浏览器上:services.gradle.org/distributions/gradle-4.1-all.zip 

即可下载,当然你也可以去网络上搜索下载。下载其他版本更改版本号就行啦,

如:services.gradle.org/distributions/gradle-3.3-all.zip

把下载下来的zip包,拷贝到如上图wrapper/dists 目录下

然后重启AS,AS会自己解压刷新等,就OK啦(建议还是选择网络好点的地方)