Android Studio - java.io.IOException: 無法生成 v1 簽名

2022-09-04 03:57:07

在3.0 Canary 4之后将我的Android Studio更新到所有新版本后,我收到此错误。(我使用的是 v3.0,因为它要快得多,而且不需要为 Kotlin 插孔。

构建流程似乎存在一个问题,无法为调试版本和发布版本生成或签署我的APK文件。

我也尝试删除我的,重新启动AndroidStudio和system(!!!),但它没有解决。debug.keystore

这是一个完整的Gradle日志:

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

答案 1

使用命令进行更多调查后,我发现APK压缩过程出现问题:gradle assemble --stacktrace

错误:org.gradle.tooling.BuildException: 无法生成 v1 签名 错误:java.io.IOException: 无法生成 v1 签名 错误:com.android.apksig.apk.ApkFormatException: 不受支持的字符0x0d在 ZIP 条目名称“assets/Icon?”

在我的项目中有一个名为“Icon?”的文件,这是一个MacOS文件,指示文件夹的图标,其中包含字符。CR, LF

我删除了该文件,现在一切正常。

在Android Studio Canary 4之后,这个问题出现在所有版本中,我在这个线程上向Android Studio团队报告了这个问题 https://issuetracker.google.com/issues/63885809

他们提到:

3.0 Canary 4大约是我们添加“不支持的字符”检查的时间,所以这就是为什么它从该版本开始发生的原因。

他们正在调查更多以解决此问题,我希望这个答案可以帮助其他人不要浪费一个月的时间不更新他们的Android Studio。:)


答案 2

最初,我开始有很多错误“文件名必须以.xml或.png结尾(我也使用Mac OSX),然后我开始删除一堆随机图标文件,我发现分散在周围。最终收到新错误“任务':app:packageDebug'执行失败,无法生成v1签名”

最后,得到了一个很好的建议,尝试构建>清理项目,然后重新编译。这将强制 IDE 再次查看文件,然后重试)。如果您删除了图标文件,Android Studio 可能需要为该项目重新编制索引。


推荐