Android Studio報錯Error:Failed to open zip file. Gradle's dependency cache may be corrupt

Android Studio導入項目後,Gradle編譯失敗,報錯以下。html

Error:Failed to open zip file. Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) <a href="syncProject">Re-download dependencies and sync project (requires network)</a> <a href="syncProject">Re-download dependencies and sync project (requires network)</a>

搜了一下,這個報錯是由於項目的gradle-wrapper.properties文件中指定須要的Gradle版本不存在。以下圖,須要gradle-3.5-all.zip。網絡

在AS的Gradle設置中,Gradle Home默認的路徑是C:\Users\用戶名\.gradle\wrapper\dists\。進這個目錄看了一眼,發現的確已有了gradle-3.5-all文件夾。app

那爲什麼仍是報這個找不到gradle目標版本的錯誤?打開其餘版本的gradle目錄對比了一下,發現gradle-3.5-all.zip的大小明顯小於其餘版本的。原來是由於天朝GFW的網絡狀況,致使gradle-3.5-all.zip在聯網從下serviices.gradle.org/distributions/下載時,沒下載完整就中斷了。致使gradle-3.5無法正常使用。工具

解決辦法是本身手動到serviices.gradle.org/distributions/網站上下載gradle(可用迅雷等下載工具),下好後丟進C:\Users\用戶名\.gradle\wrapper\dists\便可。下載時填寫url地址注意是https而不是http(多了個s)。gradle

不解壓該壓縮包,打開AS打開項目,手動修改gradle-wrapper.properties中的gradle路徑問本地路徑:網站

給Gradle從新編譯後就能看到壓縮包被解壓了。完成編譯後能夠把zip壓縮包刪除。ui

 

 

參考:http://www.jcodecraeer.com/a/anzhuokaifa/Android_Studio/2017/0317/7691.htmlthis

相關文章
相關標籤/搜索