gradle 项目构建期间出现ZipException

mm9b1k5b  于 2023-02-04  发布在  其他
关注(0)|答案(3)|浏览(137)

我正在为版本3.4(版本5.1.1为gradle)更新Android Studio和插件当我尝试构建项目时,我收到错误
java.util.zip.ZipException:压缩文件是空的
我下载了www.example.com并尝试替换现有的,但没有成功。gradle-5.1.1-all.zip and tried replace existing but it was unsuccessfully.
知道是什么原因导致了这个错误吗?
原木

Caused by: org.gradle.api.tasks.TaskExecutionException: Execution     failed for task ':app:transformClassesWithDexBuilderForDevDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:119)
    at org.gradle.api.internal.tasks.execution.ResolvePreviousStateExecuter.execute(ResolvePreviousStateExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:93)

    *****

    ... 6 more
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.util.zip.ZipException: zip file is empty
    at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:230)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    *****

Caused by: com.android.build.api.transform.TransformException: java.util.zip.ZipException: zip file is empty
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.transform(DexArchiveBuilderTransform.java:442)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:239)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:235)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    ... 77 more
Caused by: java.util.zip.ZipException: zip file is empty
    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:273)
    at com.android.tools.r8.ArchiveClassFileProvider.<init>(ArchiveClassFileProvider.java:63)
    at com.android.tools.r8.ArchiveClassFileProvider.<init>(ArchiveClassFileProvider.java:50)
    at com.android.builder.dexing.r8.CachingArchiveClassFileProvider.<init>(CachingArchiveClassFileProvider.java:32)
    at com.android.builder.dexing.r8.ClassFileProviderFactory.createProvider(ClassFileProviderFactory.java:123)
    at com.android.builder.dexing.r8.ClassFileProviderFactory.<init>(ClassFileProviderFactory.java:93)
    at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.transform(DexArchiveBuilderTransform.java:363)

构建工具28.0.3

6mzjoqzu

6mzjoqzu1#

此问题的原因之一是decommissioning of HTTP services by Gradle。这意味着如果您的[PROJECT_PATH]/gradle/wrapper/gradle-wrapper.properties文件包含如下条目:

distributionUrl=http\://services.gradle.org/distributions/gradle-{version}.zip

...则该条目将尝试从不再可通过http访问的服务检索ZIP文件,并且它将静默地返回空的ZIP文件;其结果将是来自试图解压缩该空X1 M4 N1 X文件的任何进程的错误源。
要解决此问题,只需更改您的[PROJECT_PATH]/gradle/wrapper/gradle-wrapper.properties文件,使其distributionUrl条目使用https

distributionUrl=https\://services.gradle.org/distributions/gradle-{version}.zip

希望这个有用。

ldioqlga

ldioqlga2#

尝试重新创建一个gradle Package 器。在我看来,您使用的是旧版本。我用同样的方法修复了相同的问题。

ltqd579y

ltqd579y3#

这听起来像是JDK未正确安装(可能在更新时)或未正确链接到更新的Android Studio IDE中的构建版本的问题。
首先确保JDK在Android Studio中设置正确,然后再回到JDK本身,尝试在您的计算机上重新安装JDK。

相关问题