Hey Guys我是Android Studio的新手,刚刚开始通过Udacity开发这个在线课程“开发Android应用程序”。问题是我正在开发的项目与课程“ Sunshine < / strong>“未能正确同步...
这是事件日志中显示的消息..
Gradle sync失败:原因:打开zip文件时出错
日志的完整描述:
**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$resolveProjectInfo$0(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$3.execute(ExternalSystemUtil.java:415)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$5.run(ExternalSystemUtil.java:494)
at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:635)
at com.intellij.openapi.progress.impl.CoreProgressManager$3.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$1.run(ProgressManagerImpl.java:128)
at com.intellij.openapi.application.impl.ApplicationImpl$2.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.access$600(Install.java:27)
at org.gradle.wrapper.Install$1.call(Install.java:74)
at org.gradle.wrapper.Install$1.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$1.call(DistributionFactory.java:139)
at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution$1.call(DistributionFactory.java:133)
... 4 more**
有人能指出我如何解决这个问题的正确方向吗?
答案 0 :(得分:45)
只需从主目录中删除gradle文件夹即可!即
~/<username>/.gradle/wrapper/dists/<gradle-name>
其中gradle-name
是您必须删除的分配。然后打开android studio并打开项目重新同步gradle。
答案 1 :(得分:14)
引起:java.util.zip.ZipException:打开zip文件时出错
这意味着Gradle已下载的文件由于某种原因或某种原因而已损坏。这可能是Gradle本身的下载(包装器所做的)或Gradle为运行您的构建而下载的任何依赖项。
Gradle不会尝试检测或解决问题,因此您需要手动修复它。解决方案通常是清除Gradle的下载缓存,让它获得所需内容的新副本。
为此,请删除主目录和项目根目录中的.gradle
目录,然后重新构建。
在您的情况下,主目录是
C:\Users\User\.gradle
答案 2 :(得分:1)
以下是我的解决方案。
手动下载distributionUrl指定的文件,该文件在$ PROJECT / gradle / wrapper / gradle-wrapper.properties文件中定义。就我而言,该行看起来像:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
将下载的文件复制到上述gradle-wrapper.properties文件中指定的路径。在我的例子中,gradle-2.14.1-bin.zip应该放在文件夹中:
~/.gradle/wrapper/dists/gradle-2.14.1-bin/2r579t5wehc7ew5kc8vfqezww
由于gradle尝试下载gradle-2.14.1-bin.zip但失败了,因此该文件夹中的gradle-2.14.1-bin.zip已损坏。只需用手动下载的。
返回android studio并单击超链接的错误消息。它应该继续进行同步。
答案 3 :(得分:1)
此错误发生时,我创建了一个新项目。 在终端中:
cd /Users/<user>/.gradle/wrapper/dists
ls
在这里,我可以看到Android Studio正在尝试下载gradle-4.6-all,而我已经拥有gradle-4.10-all(这对我的早期项目来说是有效的)。
我删除了文件夹
rm -r gradle-4.6-all
。
在我的gradle-wrapper.properties文件中,我将分发URL替换为distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
同步了我的项目,它成功了。
答案 4 :(得分:0)
从此链接下载gradle最新版本 https://services.gradle.org/distributions/ 提取gradle目录中的文件 现在转到android studio文件&gt;设置&gt;构建&gt; exec部署更改默认gradle位置到你下载的本地gradle 单击确定并重建项目 将修复
答案 5 :(得分:0)
答案 6 :(得分:0)
~/<username>/.gradle/wrapper/dists/<gradle-name>
删除该gradle并重新安装
答案 7 :(得分:0)
在IntelliJ Ultimate 2018和2019中遇到相同的错误。
我通过以下操作解决了这个问题:
使用brew下载gradle:
brew install gradle
然后像这样设置gradle设置并重新同步。注意Gradle Home:
答案 8 :(得分:0)
此错误是由于gradle文件损坏导致的。您所要做的只是删除以下文件夹并打开Android Studio。它会自动再次开始下载gradle文件,并且可以正常工作。Delete the following folder