Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - java.io.IOException: Failed to generate v1 signature

I get this error after updating my Android Studio to all new versions after 3.0 Canary 4. (I am using v3.0 cause it is much faster and there is no need to jack for Kotlin.)

It looks like there is an issue with build flow that it cannot generate or sign my APK file for both debug and release version.

I also tried deleting my debug.keystore, restarting AndroidStudio and system(!!!) but it didn't solve.

Here is a full Gradle log:

FAILURE: Build failed with an exception.

* What went wrong: Execution failed for task ':chris-app:packageDemoDebug'.
java.io.IOException: Failed to generate v1 signature

* Try: Run with --info or --debug option to get more log output.

* Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':chris-app:packageDemoDebug'.
        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:64)
        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:243)
        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:236)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:225)
        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: java.io.IOException: Failed to generate v1 signature
        at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$10(OutputScope.java:240)
        at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:235)
        at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:196)
        at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:180)
        at com.android.build.gradle.tasks.PackageAndroidArtifact.doFullTaskAction(PackageAndroidArtifact.java:466)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:80)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:168)
        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.lang.RuntimeException: java.io.IOException: Failed to generate v1 signature Caused by: java.io.IOException: Failed to generate v1 signature
        at com.android.apkzlib.sign.SigningExtension.onOutputZipReadyForUpdate(SigningExtension.java:297)
        at com.android.apkzlib.sign.SigningExtension.access$200(SigningExtension.java:55)
        at com.android.apkzlib.sign.SigningExtension$1.lambda$beforeUpdate$2(SigningExtension.java:175)
        at com.android.apkzlib.zip.ZFile.notify(ZFile.java:2099)
        at com.android.apkzlib.zip.ZFile.update(ZFile.java:871)
        at com.android.apkzlib.zip.ZFile.close(ZFile.java:1161)
        at com.android.apkzlib.zfile.ApkZFileCreator.close(ApkZFileCreator.java:172)
        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:698)
        at com.android.build.gradle.tasks.PackageAndroidArtifact.splitFullAction(PackageAndroidArtifact.java:520)
        at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$6(OutputScope.java:185)
        at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$7(OutputScope.java:202)
        at com.android.build.gradle.internal.scope.OutputScope.lambda$null$8(OutputScope.java:224) "
        at com.android.apksig.internal.apk.v1.V1SchemeSigner.checkEntryNameValid(V1SchemeSigner.java:406)
        at com.android.apksig.internal.apk.v1.V1SchemeSigner.generateManifestFile(V1SchemeSigner.java:373)
        at com.android.apksig.internal.apk.v1.V1SchemeSigner.sign(V1SchemeSigner.java:253)
        at com.android.apksig.DefaultApkSignerEngine.outputJarEntries(DefaultApkSignerEngine.java:372)
        at com.android.apkzlib.sign.SigningExtension.onOutputZipReadyForUpdate(SigningExtension.java:295)
        ... 13 more


BUILD FAILED in 2m 49s
like image 292
Mohsen Mirhoseini Avatar asked Sep 09 '17 09:09

Mohsen Mirhoseini


1 Answers

After more investigation using gradle assemble --stacktrace command I found that the issue is with APK zipping process:

Error:org.gradle.tooling.BuildException: Failed to generate v1 signature Error:java.io.IOException: Failed to generate v1 signature Error:com.android.apksig.apk.ApkFormatException: Unsupported character 0x0d in ZIP entry name "assets/Icon?"

There was a file named "Icon?" in my project which is a MacOS file that indicates folder's icon and it contains CR, LF characters inside.

I deleted the file and now everything is working fine.

This issue showed up in all versions after Android Studio Canary 4 and I report the issue to Android Studio team on this thread https://issuetracker.google.com/issues/63885809

and they mentioned:

3.0 Canary 4 is about the time we added that "Unsupported character" check, so that's why it happens from that version forward.

They are investigating more to solve this issue and I hope this answer helps others not to waste one month not updating their Android Studio. :)

like image 83
Mohsen Mirhoseini Avatar answered Nov 01 '22 01:11

Mohsen Mirhoseini