gpt4 book ai didi

visual-studio - Visual Studio 的 AndroidApkSigner 在 keystore 中找不到 key

转载 作者:行者123 更新时间:2023-12-02 00:59:45 27 4
gpt4 key购买 nike

在 Visual Studio 中创建 APK 时出现此错误:

Failed to load signer "signer #1": C:\...\googleplay.keystore entry "googleplay" does not contain a key

我是熟悉 Visual Studio 的长期 ASP.NET 开发人员,但这是我的第一个 Xamarin 项目。 (我没有使用 Android Studio。)我正在尝试将 Android 版本部署到 Google Play。我从来没有上传过APK到Google Play,所以我无法使用Visual Studio的自动部署;我必须首先按照 Google 和 Microsoft 的说明执行手动部署。

我正在使用 JDK 1.8 运行 Visual Studio 2017 15.7.5(最新)。我的项目使用 NETStandard.Library 2.0.3、Xamarin.Forms 3.1.0 和 Microsoft.EntityFrameworkCore 2.1.1。

这个问题类似于 this question that has no answers但我从 Visual Studio 中收到错误消息。如果这是重复的,我深表歉意,但我无法添加有关该问题的其他详细信息。

我正在使用 Google Play 应用签名。我已经通过 Google Play 创建了一个 key 。我下载了 .der 格式的证书。我使用 keytool(来自 c:\Program Files\Java\jdk1.8.0_172\bin)使用以下命令将 .der 文件转换为 .keystore:
keytool -importcert -alias googleplay -file "C:\...\deployment_cert.der"

我已经多次重新运行此实用程序更改了选项,认为 keytool 提示的别名或密码中的特殊字符可能存在区分大小写的问题。在这种情况下,别名全是字母,全是小写,密码是全小写的字母数字。 keytool 要求信任此证书,然后我按“y”。

这会生成一个名为 .keystore 的文件。 .我将其重命名为 googleplay.keystore我把它搬到了一个更合适的地方。

我可以仔细检查 googleplay通过运行以下命令,别名出现在 keystore 文件中:
C:\Program Files\Java\jdk1.8.0_172\bin>keytool -v -list -keystore "C:\...\googleplay.keystore" -alias googleplay
Enter keystore password:
Alias name: googleplay
Creation date: Jul 23, 2018
Entry type: trustedCertEntry

Owner: CN=Android, OU=Android, O=Google Inc., L=Mountain View, ST=California, C=US
Issuer: CN=Android, OU=Android, O=Google Inc., L=Mountain View, ST=California, C=US
Serial number: e8************************************8a
Valid from: Thu Jul 19 14:18:56 EDT 2018 until: Sun Jul 19 14:18:56 EDT 2048
Certificate fingerprints:
MD5: 0D:**:**:**:**:**:**:**:**:**:**:**:**:**:**:C8
SHA1: 11:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:CD
SHA256: D0:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:74
Signature algorithm name: SHA256withRSA
Subject Public Key Algorithm: 4096-bit RSA key
Version: 3

Extensions:

#1: ObjectId: 2.5.29.19 Criticality=false
BasicConstraints:[
CA:true
PathLen:2147483647
]

“googleplay”别名绝对存在!证书指纹与 Google 给我的 key 相匹配(已编辑)。

在Visual Studio中,我将解决方案配置设置为Release模式,我清理了我的整个解决方案(成功),重建了我的整个解决方案(成功),然后右键单击了我的Android项目并单击了 Archive...these instructions .

作为旁注,微软的那篇文章非常令人沮丧,因为它没有提到签名或这个问题,以及他们的 articlessigning与 Google Play 的运作方式不匹配,并且似乎假设您已经将正确的 APK 上传到 Google Play(绕过了鸡或蛋的 Catch-22)。

起初我得到的是 The archiving process has failed. Please see the Errors section for more details.错误列表面板是空的。输出面板只是说 "java.exe" exited with code 2.我去了 Tools -> Options -> Projects and Solutions -> Build and Run并更改 MSBuild project build output verbosity来自 MinimalDiagnostic并重复最后几个步骤(清理、重建、存档)。现在,输出面板(略有编辑)说:
Using "AndroidApkSigner" task from assembly "C:\...\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll".
Task "AndroidApkSigner"
AndroidApkSigner:
ApkSignerJar: C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\lib\apksigner.jar
ApkToSign: bin\Release\com.mycompany.myproject.apk
ManifestFile: obj\Release\android\AndroidManifest.xml
AdditionalArguments:
C:\Program Files\Java\jdk1.8.0_172\\bin\java.exe -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\lib\apksigner.jar" sign --ks "C:\...\googleplay.keystore" --ks-pass pass:******** --ks-key-alias googleplay --key-pass pass:******** --min-sdk-version 19 --max-sdk-version 27 C:\...\myproject.Android\bin\Release\com.mycompany.myproject.apk
Failed to load signer "signer #1": C:\...\googleplay.keystore entry "googleplay" does not contain a key
"java.exe" exited with code 2.
Done executing task "AndroidApkSigner" -- FAILED.
Done building target "_Sign" in project "myproject.Android.csproj" -- FAILED.
Done building project "myproject.Android.csproj" -- FAILED.
Build FAILED.

从上面的输出中,您可以看到我的项目属性的 Android 包签名选项卡中的(编辑)值是什么。通过反复试验,我发现 keystore 密码、别名和别名密码都是必需的。我将 keystore 密码和别名密码设置为相同,因为只有一个密码与此 keystore 相关联。如上所述,密码是小写字母数字(在另一个 SO 问题的建议之后没有特殊字符)。

当 keytool 毫无问题地找到 key 时,为什么 AndroidApkSigner 无法在提供的别名的 keystore 中找到 key ?

而且,我不能是唯一一个遇到这个问题的人吗?从 Visual Studio 部署到 Google Play 应该是一个相当常见的工作流程,但我没有找到其他人(除了 this other unanswered SO question )遇到这个问题。我究竟做错了什么?

最佳答案

我已经找到了我的问题的答案。 documentation on the Android Developer site不适用于 Visual Studio。 Xamarin 自带的 ApkSigner 不知道用它做什么。相反,使用它来创建您自己的发布 key :

keytool -v -list -keystore c:\temp\myreleasekey.keystore -alias myalias -storetype pkcs12

请注意 -storetype pkcs12在末尾。该命令也被修改为(1)将文件写入除 Program Files 之外的某处,(2)使用 .keystore Visual Studio 喜欢的扩展名,并且 (3) 避免了别名中的特殊字符,这是 Visual Studio 不喜欢的,从我读过的内容来看。 (也要避免密码中的特殊字符。)

注意, keytool位于 c:\Program Files\Java\jdk[version]\bin .

线索

当我按照 the documentation 上的说明进行操作时, 我收到了来自 keytool 的警告:

Warning: The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using keytool -importkeystore -srckeystore c:\temp\myreleasekey.jks -destkeystore c:\temp\myreleasekey.jks -deststoretype pkcs12.



验证 key 正确时,我也收到此警告:
keytool -v -list -keystore c:\temp\myreleasekey.jks -alias myalias

如果您有一个现有的 key 并需要转换它,请按照警告中的命令进行操作。

谢谢:

我要感谢 Nick 解释了签署和区分所有 key 背后的原因。

谢谢你,Jon,他为我指明了如何创建我自己的私钥。

关于visual-studio - Visual Studio 的 AndroidApkSigner 在 keystore 中找不到 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51481342/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com