Android Studio - java.io.IOException:无法生成 v1 签名

Posted

技术标签:

【中文标题】Android Studio - java.io.IOException:无法生成 v1 签名【英文标题】:Android Studio - java.io.IOException: Failed to generate v1 signature 【发布时间】:2018-02-18 03:26:59 【问题描述】:

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

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

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

这是完整的 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】:

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

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

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

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

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

他们提到:

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

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

【讨论】:

我仍然在稳定的 Android Studio 3.0.0 版本中看到这一点。 @JohanPaul 是的,这种变化将持续存在!您必须找到该文件并将其删除。 我从命令行做了一个 Gradle 构建,它是成功的。在此之后,我也可以再次从 AS 3.0 构建。这对我来说毫无意义。 @JohanPaul 这是真的。将项目与 Gradle 文件同步(使用 AS 工具栏上的相关按钮)会有所帮助,主要是在您在不同的构建工具版本之间切换时。【参考方案2】:

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

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

【讨论】:

以上是关于Android Studio - java.io.IOException:无法生成 v1 签名的主要内容,如果未能解决你的问题,请参考以下文章

Android Studio - ProGuard“java.io.IOException ...bin\classes(没有这样的文件或目录)”

错误:任务“:app:processDebugResources”执行失败。 > java.io.IOException: 无法在 android studio 中删除文件夹“”

我的Android进阶之旅解决Android Studio报错:Caused by: java.io.StreamCorruptedException: invalid type code: 00

Android Studio Termanal打不开,提示java.io.IOEXception:couldn't create PTY

Android Studio报错:java.io.IOException: Cleartext HTTP traffic to XXX not permitted

Android Studio 意外的内容存储修改