Java Gradle 同步失败:原因:打开 zip 文件时出错 Corrupt Dependency Cache
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42591546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle sync failed: Cause: error in opening zip file Corrupt Dependency Cache
提问by Nikhilesh Chaudhary
I am new to Android Studio and just started learning through this online course 'Developing Android Apps' by Udacity..The problem is that the project which I am developing keeping in line with the course "Sunshine" is failing to sync properly.
我是 Android Studio 的新手,刚刚开始学习 Udacity 的在线课程“开发 Android 应用程序”。问题是我正在开发的与课程“阳光”保持一致的项目未能正确同步。
This is the message displayed in event logs.
这是事件日志中显示的消息。
Gradle sync failed: Cause: error in opening zip file
Gradle 同步失败:原因:打开 zip 文件时出错
Full description of logs:
日志的完整描述:
**2017-03-04 08:14:32,358 [ 61978] WARN - nal.AbstractExternalSystemTask - Cause: error in opening zip file
com.intellij.openapi.externalSystem.model.ExternalSystemException: Cause: **error in opening zip file**
at com.android.tools.idea.gradle.project.sync.idea.ProjectImportErrorHandler.getUserFriendlyError(ProjectImportErrorHandler.java:86)
at com.android.tools.idea.gradle.project.sync.idea.AndroidGradleProjectResolver.getUserFriendlyError(AndroidGradleProjectResolver.java:361)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:769)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:749)
at org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper.execute(GradleExecutionHelper.java:227)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:112)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:72)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.lambda$resolveProjectInfoC:\Users\User\.gradle
(RemoteExternalSystemProjectResolverImpl.java:37)
at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:59)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:37)
at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:49)
at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:51)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:138)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:124)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil.execute(ExternalSystemUtil.java:415)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil.run(ExternalSystemUtil.java:494)
at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:635)
at com.intellij.openapi.progress.impl.CoreProgressManager.run(CoreProgressManager.java:170)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:494)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:443)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:155)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.run(ProgressManagerImpl.java:128)
at com.intellij.openapi.application.impl.ApplicationImpl.run(ApplicationImpl.java:307)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.zip.ZipException: **error in opening zip file**
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:219)
at java.util.zip.ZipFile.<init>(ZipFile.java:149)
at java.util.zip.ZipFile.<init>(ZipFile.java:163)
at org.gradle.wrapper.Install.unzip(Install.java:214)
at org.gradle.wrapper.Install.access0(Install.java:27)
at org.gradle.wrapper.Install.call(Install.java:74)
at org.gradle.wrapper.Install.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution.call(DistributionFactory.java:139)
at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution.call(DistributionFactory.java:133)
... 4 more**
Can someone point me in the right direction on how to resolve this issue?
有人能指出我如何解决这个问题的正确方向吗?
回答by Aryan
Caused by: java.util.zip.ZipException: error in opening zip file
引起:java.util.zip.ZipException:打开 zip 文件时出错
This mean that a file that Gradle has downloaded has become corrupted due to somehow or some reason. This might be the download of Gradle itself (which the wrapper does) or any dependency that Gradle has downloaded to run your build.
这意味着 Gradle 下载的文件由于某种原因或某种原因已损坏。这可能是 Gradle 本身的下载(包装器会这样做)或 Gradle 为运行您的构建而下载的任何依赖项。
Gradle doesn't attempt to detect or resolve the problem, so you need to fix it manually. The solution is often to purge Gradle's download caches and let it get fresh copies of what it needs.
Gradle 不会尝试检测或解决问题,因此您需要手动修复它。解决方案通常是清除 Gradle 的下载缓存,让它获得所需内容的新副本。
To do that, delete the .gradle
directories in both your home directoryand in your project's root directoryand try building again.
要做到这一点,删除.gradle
在这两个目录的主目录,并在你的项目的根目录,然后再试一次建设。
In your case home directory is
在您的情况下,主目录是
~/<username>/.gradle/wrapper/dists/<gradle-name>
回答by Ahmad A.A
Simply delete the gradle folder from your home directory! i.e
只需从您的主目录中删除 gradle 文件夹即可!IE
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
where gradle-name
is the distribution you have to delete. Then open android studio and open the project to sync the gradle afresh.
gradle-name
您必须删除的分布在哪里。然后打开android studio并打开项目以重新同步gradle。
回答by Super apps
Download gradle latest version from this link https://services.gradle.org/distributions/Extract files in your gradle directory now go to android studio file>setting>build>exec deployment change default gradle location to to local gradle that you downloaded click ok and rebuild project that will fix
从此链接下载 gradle 最新版本 https://services.gradle.org/distributions/提取 gradle 目录中的文件现在转到 android studio file>setting>build>exec 部署将默认 gradle 位置更改为您下载的本地 gradle 单击好的并重建将修复的项目
回答by ironmann350
the problem is that android studio/gradle doesn't have the permission to access the files in your project folder.
to correct this go to your project folder > properties > security > edit and select full control for your current user or all of them
问题是 android studio/gradle 没有访问项目文件夹中文件的权限。要纠正此问题,请转到您的项目文件夹 > 属性 > 安全性 > 编辑并为当前用户或所有用户选择完全控制
回答by jhuai
The following is my solution.
以下是我的解决方案。
Manually download the file specified by distributionUrl which is defined in file $PROJECT/gradle/wrapper/gradle-wrapper.properties. In my case, the line looks like:
~/.gradle/wrapper/dists/gradle-2.14.1-bin/2r579t5wehc7ew5kc8vfqezww
Copy the downloaded file to the path specified in the aforementioned gradle-wrapper.properties file. In my case, the gradle-2.14.1-bin.zip should be put into the folder:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
Since gradle has tried to download gradle-2.14.1-bin.zip but failed, it has a broken gradle-2.14.1-bin.zip in that folder. Simply replace the broken one with the manually downloaded.
Go back to android studio and click on the hyperlinked error message. It should proceed to synchronize.
手动下载由 distributionUrl 指定的文件,该文件在文件 $PROJECT/gradle/wrapper/gradle-wrapper.properties 中定义。就我而言,该行如下所示:
~/.gradle/wrapper/dists/gradle-2.14.1-bin/2r579t5wehc7ew5kc8vfqezww
将下载的文件复制到上述 gradle-wrapper.properties 文件中指定的路径。在我的情况下, gradle-2.14.1-bin.zip 应该放在文件夹中:
cd /Users/<user>/.gradle/wrapper/dists ls
由于 gradle 尝试下载 gradle-2.14.1-bin.zip 但失败了,因此该文件夹中的 gradle-2.14.1-bin.zip 已损坏。只需用手动下载的替换损坏的。
返回 android studio 并单击超链接的错误消息。它应该继续同步。
回答by DISHA
I had created a new project when this error came. In the terminal :
出现此错误时,我创建了一个新项目。在终端:
~/<username>/.gradle/wrapper/dists/<gradle-name>
Here I could see that Android studio was trying to download gradle-4.6-all while I already had gradle-4.10-all(this was working for me for earlier projects).
I removed the folder
rm -r gradle-4.6-all
.
在这里我可以看到 Android studio 试图下载 gradle-4.6-all 而我已经有了 gradle-4.10-all(这对我早期的项目有用)。我删除了文件夹
rm -r gradle-4.6-all
。
In my gradle-wrapper.properties file, I replaced distribution URL with distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
Synched my project, and it worked.
在我的 gradle-wrapper.properties 文件中,我用distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
Synched 我的项目替换了分发 URL ,并且它起作用了。
回答by sheraz Ahmed
delete that gradle and install it again
删除该gradle并重新安装
回答by jmojico
Experienced same error in IntelliJ Ultimate 2018 and 2019.
在 IntelliJ Ultimate 2018 和 2019 中遇到同样的错误。
I fixed this issueby doing this :
Download gradle using brew:
brew install gradle
Then setup gradle settings like this and resync. Pay atention to Gradle Home:
我通过这样做解决了这个问题:
使用 brew 下载 gradle:
brew install gradle
然后像这样设置 gradle 设置并重新同步。关注Gradle首页:
回答by Aneeb Afzal
This error causes due to the corrupt gradle file. All you have to do is simply delete the following folder and open Android Studio. It will automatically start downloading gradle file again and it will work fine.Delete the following folder
由于 gradle 文件损坏而导致此错误。您所要做的就是删除以下文件夹并打开 Android Studio。它会自动重新开始下载 gradle 文件,它会正常工作。删除以下文件夹