Cordova发布版本错误:无法从商店中读取关键示例...无法恢复密钥

时间:2018-02-09 22:43:04

标签: android cordova

我试图发布一个已更新并准备部署的继承Cordova项目,但是当我尝试构建一个版本时它会抛出此错误:

命令

cordova build android -- --keystore="D:/keys/example.keystore" --storePassword=******** --alias=example

错误

:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:validateSigningDebug
:packageDebug FAILED

BUILD FAILED

Total time: 1.836 secs
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':packageDebug'.
> com.android.ide.common.signing.KeytoolException: Failed to read key example from store "D:\Projects\example\app\src\android\platforms\android\..\..\..\..\..\..\..\keys\example.keystore": Cannot recover key

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
(node:6552) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':packageDebug'.
> com.android.ide.common.signing.KeytoolException: Failed to read key example from store "D:\Projects\example\app\src\android\platforms\android\..\..\..\..\..\..\..\keys\example.keystore": Cannot recover key

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
(node:6552) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

所以我开始研究错误并发现StackOverflow上似乎有类似的错误,并且他们都说Failed to ready <alias> from store以下部分似乎是错误的区别部分,据我所知这是不是重复,因为其余的似乎都与错误的密码或密钥篡改有关。

已尝试的内容

  1. 最初,我认为之前的开发人员提供了一个无效的别名,所以我发现我可以使用keytool -list -v -keystore example.keystore来查看证书,并且只有一个条目且密钥库别名是正确的

  2. 我尝试使用标记来获取有关错误的更多信息,例如:--info--debug--stacktrace;并且他们都没有提供任何见解

  3. 发现我可以在Cordova项目中使用./gradlew signingReport,但输出重申失败,因为Cannot recover key

  4. Google现在将管理密钥签名,因此我打算上传密钥库并开始执行需要创建应用程序签名私钥的步骤,这证实了商店密码,别名和密钥密码是正确的,因为我能够创建上传的私钥。我还没有上传私钥,因为我不知道如果有任何问题会发生什么,所以我想在继续之前手动签署版本

  5. 运行keytool -list -v -keystore example.keystore来仔细检查别名,我注意到输出底部有一条消息,我用它来创建一个行业标准格式的新密钥库:

    警告: JKS密钥库使用专有格式。建议 迁移到PKCS12,这是一种行业标准格式使用 &#34; keytool -importkeystore -srckeystore NAME-mobileapps.keystore -destkeystore NAME-mobileapps.keystore -deststoretype pkcs12

  6. 再次运行发布版本,但使用更新的密钥库会在构建中的同一点产生一组新错误,因此我假设这样做是错误的:

    :validateSigningDebug
    :packageDebug FAILED
    
    BUILD FAILED
    
    Total time: 2.224 secs
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':packageDebug'.
    > com.android.ide.common.signing.KeytoolException: Failed to read key example from store "D:\Projects\example\app\src\android\platforms\android\..\..\..\..\..\..\..\downloads\example-new.keystore": Get Key failed: Given final block not properly padded
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    (node:20144) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':packageDebug'.
    > com.android.ide.common.signing.KeytoolException: Failed to read key example from store "D:\Projects\example\app\src\android\platforms\android\..\..\..\..\..\..\..\downloads\example-new.keystore": Get Key failed: Given final block not properly padded
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    (node:20144) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    
    1. 目前我正在根据原始错误中的Unhandled promise rejection查看潜在的gradle问题,但我现在只是猜测,因为这可能是内部的并且与Cannot recover key <相关/ LI>

      问题

      我昨天花了一整天的时间试图解决这个问题。任何人都可以建议如何构建和签署此版本?

2 个答案:

答案 0 :(得分:2)

我无法弄清楚为什么使用该命令不起作用,但我确实通过做一堆单独的终端命令找到了解决方法:

  1. cordova build --release android
  2. jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore D:/keystores/example.keystore ./platforms/android/build/outputs/apk/android-release-unsigned.apk example_alias
  3. zipalign -v 4 ./platforms/android/build/outputs/apk/android-release-unsigned.apk ./release/example-release-signed.apk

答案 1 :(得分:0)

@mtpultz

此格式适用于Windows

  1. cordova build --release android

  2. & 'C:\Program Files\Java\jdk1.8.0_161\bin\jarsigner.exe' -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore 'D:/Projects/Resources/key.jks' './platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk' example-keyalias

  3. & 'C:\Users\Machine\AppData\Local\Android\Sdk\build-tools\27.0.3\zipalign.exe' -v 4 './platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk' './platforms/android/app/build/outputs/apk/release/app-release-signed.apk'