java.io.IOException: EOCD signature not found in the last 0 bytes of the file


(Lyle) #1

When added

     applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = null
                if (variant.buildType.name == 'debug') {
                    fileName = "dbikedebug"
                } else if (variant.buildType.name == 'test') {
                    fileName = "dbiketest"
                } else if (variant.buildType.name == 'pre') {
                    fileName = "dbikepre"
                } else if (variant.buildType.name == 'release') {
                    fileName = "dbike"
                }  fileName = fileName + "${defaultConfig.versionName}" + ".apk"
                outputFileName = fileName
            }
        }
    }

build apk will get error:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app: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.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
	at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
	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:197)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
	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:124)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
	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: Failed to read zip file '/Users/xuleyuan/SanTong/SanTongAndroid/app/build/outputs/apk/debug/dbikedebug1.2.28.apk'.
	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:471)
	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.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
	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:197)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
	... 27 more
Caused by: java.io.IOException: Failed to read zip file '/Users/xuleyuan/SanTong/SanTongAndroid/app/build/outputs/apk/debug/dbikedebug1.2.28.apk'.
	at com.android.apkzlib.zip.ZFile.<init>(ZFile.java:464)
	at com.android.apkzlib.zfile.ZFiles.apk(ZFiles.java:68)
	at com.android.apkzlib.zfile.ZFiles.apk(ZFiles.java:103)
	at com.android.apkzlib.zfile.ApkZFileCreator.<init>(ApkZFileCreator.java:95)
	at com.android.apkzlib.zfile.ApkZFileCreatorFactory.make(ApkZFileCreatorFactory.java:49)
	at com.android.builder.internal.packaging.IncrementalPackager.<init>(IncrementalPackager.java:127)
	at com.android.build.gradle.internal.packaging.IncrementalPackagerBuilder.build(IncrementalPackagerBuilder.java:379)
	at com.android.build.gradle.tasks.PackageAndroidArtifact.doTask(PackageAndroidArtifact.java:687)
	at com.android.build.gradle.tasks.PackageAndroidArtifact.splitFullAction(PackageAndroidArtifact.java:522)
	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)
Caused by: java.io.IOException: EOCD signature not found in the last 0 bytes of the file.
	at com.android.apkzlib.zip.ZFile.readEocd(ZFile.java:681)
	at com.android.apkzlib.zip.ZFile.readData(ZFile.java:535)
	at com.android.apkzlib.zip.ZFile.<init>(ZFile.java:457)
	... 11 more

Environment:
Grade:3.0.0
Plugins:distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
AndroidStudio:3.0
Hope some helps~~


(Lyle) #2

I’ve fixed that.
Generate different abi apks need different apk name .
So I changed
outputFileName = fileName + ".apk"
to
outputFileName = fileName + output.getFilter(com.android.build.OutputFile.ABI)+ ".apk"


(Rupali Chawla) #3

How to change the output file name?


(Lyle) #4

Just modify the outPutFileName in the topic I paste