Java Android studio - 无法完成 gradle 执行 - 打开 zip 文件时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23828085/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:26:50  来源:igfitidea点击:

Android studio - Failed to complete gradle execution - error in opening zip file

javaandroidgradleandroid-studioandroid-gradle-plugin

提问by Omri Btian

I'm new to android development and android studio IDE.

我是 android 开发和 android studio IDE 的新手。

I've checked-out a project from bitbucket and when I try to compile it I get the following error:

我已经从 bitbucket 签出一个项目,当我尝试编译它时,出现以下错误:

Failed to complete Gradle Execution

Cause: error in opening zip file.

无法完成 Gradle 执行

原因:打开 zip 文件时出错。

My gradle-wrapper.propertiesis as follows:

gradle-wrapper.properties的如下:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip

I wasn't able to get too much information from this but the full log states:

我无法从中获得太多信息,但完整的日志指出:

2014-05-23 14:06:28,950 [ 32077] WARN - nal.AbstractExternalSystemTask - Cause: error in opening zip file com.intellij.openapi.externalSystem.model.ExternalSystemException: Cause: error in opening zip file at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:206) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:116) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:64) at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:41) at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(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:48) at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:137) at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:123) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3.execute(ExternalSystemUtil.java:467) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$4$2.run(ExternalSystemUtil.java:546) at com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:464) at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178) at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212) at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171) at com.intellij.openapi.progress.impl.ProgressManagerImpl$8.run(ProgressManagerImpl.java:373) at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:419) 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) at com.intellij.openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:149)

2014-05-23 14:06:28,950 [ 32077] WARN - .project.GradleProjectImporter - 2014-05-23 14:06:28,951 [ 32078]
INFO - .project.GradleProjectImporter - Cause: error in opening zip file

2014-05-23 14:06:28,950 [32077] 警告 - nal.AbstractExternalSystemTask - 原因:打开 zip 文件 com.intellij.openapi.externalSystem.model.ExternalSystemException 时出错:原因:在 org.jetbrains 打开 zip 文件时出错。 plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:206) 在 org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:116) 在 org.jetbrains.plugins.gradle。 service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:64) at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:41) at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:41) at com.intellij.openapi.externalSystem.service.remote.remoteExternalSystemProjectResolverImpl.java:41) .RemoteExternalSystemProjectResolverImpl$1。com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:59) 处的生产(RemoteExternalSystemProjectResolverImpl.java:37) com.intellij.openapi.externalSystem.service.remoteProjectInforsolverImpl. java:37) 在 com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:49) 在 com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.dosolve(TaskExternalSystem) 48) 在 com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:137) 在 com.intellij.openapi。externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:123) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3.execute(ExternalSystemUtil.java:467) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil $4$2.run(ExternalSystemUtil.java:546) 在 com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:464) 在 com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run( ProgressManagerImpl.java:178) at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212) at com.intellij .openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171) 在 com.intellij.openapi.progress.impl.ProgressManagerImpl$8.run(ProgressManagerImpl.java:373) 在 com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:419) 在 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) 在 java.lang.Thread.run(Thread.java:745) 在 com.intellij.openapi.application.impl.ApplicationImpl$1$1.run( ApplicationImpl.java:149)419) 在 java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 在 java.util.concurrent.FutureTask.run(FutureTask.java:266) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor) .java:1142) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 在 java.lang.Thread.run(Thread.java:745) 在 com.intellij.openapi.application.impl。 ApplicationImpl$1$1.run(ApplicationImpl.java:149)419) 在 java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 在 java.util.concurrent.FutureTask.run(FutureTask.java:266) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor) .java:1142) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 在 java.lang.Thread.run(Thread.java:745) 在 com.intellij.openapi.application.impl。 ApplicationImpl$1$1.run(ApplicationImpl.java:149)openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:149)openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:149)

2014-05-23 14:06:28,950 [32077] 警告 - .project.GradleProjectImporter - 2014-05-23 14:06:28,951 [32078]
信息 - .project.GradleProject :Importer文件打开错误 - 原因

I'm using Android studio 0.5.2.

我正在使用 Android Studio 0.5.2。

Can someone point me in the right direction on how to solve this?

有人可以指出我如何解决这个问题的正确方向吗?

采纳答案by Scott Barta

An "error in opening zip file" tends to mean that a file that Gradle has downloaded has somehow become corrupted -- this might be the download of Gradle itself (which the wrapper does), or a dependency that Gradle has downloaded to run your build.

“打开 zip 文件时出错”往往意味着 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. To do that, delete the .gradledirectories in both your home directory and in your project's root directory and try building again.

Gradle 不会尝试检测或解决问题,因此您需要手动修复它。解决方案通常是清除 Gradle 的下载缓存,让它获得所需内容的新副本。为此,请删除.gradle主目录和项目根目录中的目录,然后再次尝试构建。

回答by HadenRobert

I fixed this issue by...

我通过...解决了这个问题

  • Going to Settings... > Gradle
  • Selecting "Use local Gradle distribution."
  • Pointed it to my Gradle zip file: home/kersting/.gradle/wrapper/dists/gradle-1.12-all/6vpvhqu0efs1fqmqr2decq1v12/gradle-1.12
  • 转到设置...> Gradle
  • 选择“使用本地 Gradle 分发版”。
  • 将它指向我的 Gradle zip 文件:home/kersting/.gradle/wrapper/dists/gradle-1.12-all/6vpvhqu0efs1fqmqr2decq1v12/gradle-1.12

It should be something similar for you if you downloaded Gradle which you should have when you downloaded Android Studio. Be careful, the .gradle file may be hidden. I found it through the terminal, but "ls" didn't reveal it.

如果您下载了在下载 Android Studio 时应该拥有的 Gradle,它应该与您类似。请注意,.gradle 文件可能被隐藏。我通过终端找到了它,但“ls”没有显示它。

回答by Ali

I had the same problem, happened after turning on and off Hyman and jill tool chain. I tried removing .gradle but it didn't help. Removing the builddirectory inside my project folder resolves the problem.

我有同样的问题,在打开和关闭 Hyman 和 jill 工具链后发生。我尝试删除 .gradle 但它没有帮助。删除我的项目文件夹中的构建目录可以解决问题。

Try this before removing .gradle as it will need near 200MB worth of download.

在删除 .gradle 之前试试这个,因为它需要将近 200MB 的下载量。

回答by Ali

I fixed the same issue via the following:

我通过以下方式解决了同样的问题:

Go to File -> Settings -> Gradle

转到文件 -> 设置 -> Gradle

Input the following in the "Gradle VM options:" box: -XX:MaxHeapSize=256m -Xmx256m

在“Gradle VM options:”框中输入以下内容:-XX:MaxHeapSize=256m -Xmx256m

Hit apply and Android Studio should build your project successfully.

点击应用,Android Studio 应该会成功构建您的项目。

回答by Khurshid A Bhuyan

If you have limited internet plan then use the following method.

如果您的互联网计划有限,请使用以下方法。

Step1: Close android studio

第一步:关闭安卓工作室

Step2: Go to C:\Users\Khurshid\.gradle\wrapper\dists\gradle-1.12-all\2apkk7d25miauqf1pdjp1bm0uo(if you want to configure gradle 1.12)

Step2:转到 C:\Users\Khurshid\.gradle\wrapper\dists\gradle-1.12-all\2apkk7d25miauqf1pdjp1bm0uo(如果你想配置 gradle 1.12)

Step3: try to open the gradle-1.12-all.zip by double clicking it. If it gives error message then delete the zip file.

Step3:尝试双击打开gradle-1.12-all.zip。如果它给出错误消息,则删除 zip 文件。

step4: go to https://services.gradle.org/distributionsand download gradle-1.12-all.zip (54mb approx) and copy the same to the folder where you have previously deleted the zip file.

第 4 步:转到https://services.gradle.org/distributions并下载 gradle-1.12-all.zip(约 54mb)并将其复制到您之前删除 zip 文件的文件夹中。

step5: open android studio and go to file->setting select 'gradle' and click on 'use local gradle distribution' and set 'gradle home' to 'C:\Users\Khurshid\.gradle\wrapper\dists\gradle-1.12-all\2apkk7d25miauqf1pdjp1bm0uo\gradle-1.12-all.zip' and click ok.

步骤5:打开android studio并转到文件->设置选择“gradle”并单击“使用本地gradle分发”并将“gradle home”设置为“ C:\Users\Khurshid\.gradle\wrapper\dists\gradle-1.12 -all\2apkk7d25miauqf1pdjp1bm0uo\gradle-1.12-all.zip' 然后点击确定。

step6: It will download some file over the internet. If download doesn't start automatically then restart android studio.

第6步:它将通过互联网下载一些文件。如果下载未自动开始,则重新启动 android studio。

step7: Be patience and let it download some important stuff and after that everything should be working fine. This method will help you save your internet data. Downloading the entire gradle directory will consume double the data.

step7:耐心等待,让它下载一些重要的东西,之后一切都应该正常工作。此方法将帮助您保存您的互联网数据。下载整个 gradle 目录将消耗双倍的数据。

Thank You

谢谢你

回答by asamoylenko

Clearing .gradledirectory didn't help, but clearing builddirectory did the job for me.

清除.gradle目录没有帮助,但清除构建目录对我有用

回答by Ajay P. Prajapati

You just have to edit build.gradlefile.

你只需要编辑build.gradle文件。

you should set the classpath to the latest gradle version

您应该将类​​路径设置为最新的 gradle 版本

  dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
}

and Sync the project. All errors will be gone. What you can do is, make new project in android studio, which will have classpath of latest gradle and paste it into your project that having Cause: error in opening zip file.this error.

并同步项目。所有错误都将消失。您可以做的是,在 android studio 中创建新项目,该项目将具有最新 gradle 的类路径并将其粘贴到出现Cause: error in opening zip file.此错误的项目中。

回答by speedynomads

For me the solution to this error was to change the gradle wrapper version in ../gradle/wraper/gradle-wrapper.properties to a different/newer version.. I used:

对我来说,解决此错误的方法是将 ../gradle/wraper/gradle-wrapper.properties 中的 gradle 包装器版本更改为不同/较新的版本。我使用了:

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

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

Then call:

然后调用:

./gradlew --refresh-dependencies

./gradlew --refresh-dependencies

This tells the wrapper to point to a new version and re-download all required dependencies. I suspect the error for me was caused by an interrupted download when first building the relevant project.

这告诉包装器指向新版本并重新下载所有必需的依赖项。我怀疑我的错误是由于第一次构建相关项目时下载中断引起的。

回答by na3na3iss

I had the same problem so and to fix it i download the last version of gradle:

我遇到了同样的问题,为了解决这个问题,我下载了最新版本的 gradle:

https://services.gradle.org/distributions

https://services.gradle.org/distributions

and open the gradle in the right bar then choose gradle parameters and change the path of the old gradle into the new one.

并在右侧栏中打开 gradle 然后选择 gradle 参数并将旧 gradle 的路径更改为新的。

回答by fera10

Deleting the .gradle folder worked for me. Problem resolved after I deleted .gradle folder

删除 .gradle 文件夹对我有用。删除 .gradle 文件夹后问题解决