关于Android Studio的Failed to open zip file问题

前几天打开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)

解决方法:

我花了好几天,试了网上的各种答案,不过似乎都不适合,我把这些答案贴在下面,大家也可以参考一下。我自己的解决方法是最后一个,可以先尝试我的解决方案再倒回来试其他的。

  1. 重新下载 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!
  1. 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

  1. 修改gradle-wrapper.properties
  • Find ‘gradle-wrapper.properties’ in root project

distributionUrl=https://services.gradle.org/distributions/gradle-***-all.zip

  • Change “https” to “http”.
  1. 修改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,运行到手机上,搞定!
    运行到手机成功截图
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值