在Android Studio 3.1构建项目时出现“执行压缩失败”错误。

27

我正在尝试在Android Studio 3.1预览版中构建https://github.com/neural-nuts/Cam2Caption,但无论我使用多么古老的build.gradle,或者它都会崩溃。

Error:Execution failed for task ':Application:packageDebug'.
Execution of compression failed.

这是在执行项目清理或重新构建之后发生的。操作系统为OSX,版本较新。我正在使用我认为是默认的最新版本 build.gradle。
classpath 'com.android.tools.build:gradle:3.0.0'
...
android {
    compileSdkVersion 26
    defaultConfig {
        minSdkVersion 26
        targetSdkVersion 26
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
....
        compile "com.android.support:support-v4:26.1.0"
        compile "com.android.support:support-v13:26.1.0"
        compile "com.android.support:cardview-v7:26.1.0"
        compile "com.android.support:appcompat-v7:26.1.0"

有了堆栈跟踪,我得到了以下信息

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Application:packageDebug'.
> java.io.IOException: Execution of compression failed.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':Application:packageDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.tooling.BuildException: java.io.IOException: Execution of compression failed.
    at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$10(OutputScope.java:241)
    at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:236)
    at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:197)
    at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:181)
    at com.android.build.gradle.tasks.PackageAndroidArtifact.doFullTaskAction(PackageAndroidArtifact.java:449)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:109)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 29 more
Caused by: java.lang.RuntimeException: java.io.IOException: Execution of compression failed.
Caused by: java.io.IOException: Execution of compression failed.
    at com.android.apkzlib.zip.CentralDirectoryHeader.getCompressionInfoWithWait(CentralDirectoryHeader.java:431)
    at com.android.apkzlib.zip.ZFile.processAllReadyEntriesWithWait(ZFile.java:1749)
    at com.android.apkzlib.zip.ZFile.hasPendingChangesWithWait(ZFile.java:2623)
    at com.android.apkzlib.zfile.ApkZFileCreator.hasPendingChangesWithWait(ApkZFileCreator.java:180)
    at com.android.builder.internal.packaging.IncrementalPackager.hasPendingChangesWithWait(IncrementalPackager.java:319)
    at com.android.build.gradle.tasks.PackageAndroidArtifact.doTask(PackageAndroidArtifact.java:672)
    at com.android.build.gradle.tasks.PackageAndroidArtifact.splitFullAction(PackageAndroidArtifact.java:500)
    at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$6(OutputScope.java:186)
    at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$7(OutputScope.java:203)
    at com.android.build.gradle.internal.scope.OutputScope.lambda$null$8(OutputScope.java:225)
    Suppressed: java.io.IOException: Failed to obtain compression information for entry
        at com.android.apkzlib.zip.ZFile.processAllReadyEntries(ZFile.java:1727)
        at com.android.apkzlib.zip.ZFile.processAllReadyEntriesWithWait(ZFile.java:1741)
        at com.android.apkzlib.zip.ZFile.update(ZFile.java:904)
        at com.android.apkzlib.zip.ZFile.close(ZFile.java:1196)
        at com.android.apkzlib.zfile.ApkZFileCreator.close(ApkZFileCreator.java:189)
        at com.google.common.io.Closer.close(Closer.java:216)
        at com.android.builder.internal.packaging.IncrementalPackager.close(IncrementalPackager.java:332)
        at com.android.build.gradle.tasks.PackageAndroidArtifact.doTask(PackageAndroidArtifact.java:678)
        at com.android.build.gradle.tasks.PackageAndroidArtifact.splitFullAction(PackageAndroidArtifact.java:500)
        at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$6(OutputScope.java:186)
        at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$7(OutputScope.java:203)
        at com.android.build.gradle.internal.scope.OutputScope.lambda$null$8(OutputScope.java:225)
        at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
    Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Self-suppression not permitted
        at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
        at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:462)
        at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
        at com.android.apkzlib.zip.ZFile.processAllReadyEntries(ZFile.java:1722)
        ... 16 more
    Caused by: java.lang.IllegalArgumentException: Self-suppression not permitted
        at com.android.apkzlib.zip.compress.DeflateExecutionCompressor.immediateCompress(DeflateExecutionCompressor.java:72)
        at com.android.apkzlib.zip.compress.ExecutorCompressor.lambda$compress$0(ExecutorCompressor.java:54)
    Caused by: java.lang.OutOfMemoryError: Java heap space
Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Self-suppression not permitted
    at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:482)
    at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
    at com.android.apkzlib.zip.CentralDirectoryHeader.getCompressionInfoWithWait(CentralDirectoryHeader.java:425)
    ... 9 more
    [CIRCULAR REFERENCE:java.lang.IllegalArgumentException: Self-suppression not permitted]

* Get more help at https://help.gradle.org 
BUILD FAILED in 12s

将您的Android Studio升级到3.0.0版本。您是否也使用gradle wrapper或独立构建应用程序? - Testing Singh
我正在使用Android Studio 3.1预览版,您是指降级到稳定版吗? - Benjamin H
你使用的是哪个操作系统?Windows,macOS,Ubuntu? - Testing Singh
我正在使用 macOS。 - Benjamin H
2个回答

69

我也遇到了这个问题。这是因为我在资产中包含了一个非常大的zip文件,导致JVM没有足够的内存来构建项目。我通过在应用程序build.gradle中添加dexoptions来解决了这个问题。

android {
    dexOptions {
        javaMaxHeapSize "4g"
    } 
}

增加JVM堆大小

org.gradle.jvmargs=-Xmx4608M

像这样。前往gradle.properties查找此选项。


我还没有任何大型资产,但是却遇到了这个错误。我已经添加了这些行,但仍然出现相同的错误。 - Makalele
4
在React Native中遇到了相同的问题。 - aashir khan
@aashirkhan,你能修复这个问题吗? - Alperen ARICI
如果你在react-native中遇到了这个问题,请尝试删除node_modules文件夹,然后再次尝试。 - Surbhit Rao
1
谢谢。即使在2022年2月的React Native应用程序中,它也起作用了。 - Hashan Shalitha
显示剩余2条评论

0

这在我的 macOS 上突然发生了。在我的情况下,重启电脑后错误消失了...很奇怪。


你可能忘记了执行 gradlew --stop 然后再运行 Android。 - Rushabh Gedam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接