在 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。
这个问题类似于这个没有答案的问题,但我从 Visual Studio 中得到了错误。如果这是重复的,我很抱歉,但我无法添加有关该问题的其他详细信息。
我正在使用 Google Play 应用签名。我通过 Google Play 创建了一个密钥。我下载了 .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
我可以通过运行以下命令来仔细检查密钥库文件中是否存在别名:
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 给我的密钥相匹配(已编辑)。
在 Visual Studio 中,我将解决方案配置设置为发布模式,我清理了我的整个解决方案(成功),重建了我的整个解决方案(成功),然后右键单击我的 Android 项目并Archive...
按照这些说明单击。
作为旁注,微软的那篇文章非常令人沮丧,因为它没有提到签名或这个问题,而且他们关于签名的文章与 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
从Minimal
to更改Diagnostic
并重复了最后几个步骤(清理、重建、存档)。现在,输出面板(略有编辑)说:
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 Package Signing 选项卡中的(编辑的)值是什么。通过反复试验,我发现 Keystore 密码、别名和别名密码都是必需的。我将密钥库密码和别名密码设置为相同,因为只有一个密码与此密钥库关联。如上所述,密码是低字母数字(根据另一个 SO 问题的建议没有特殊字符)。
当 keytool 没有问题地找到密钥时,为什么 AndroidApkSigner 无法在提供的别名的密钥库中找到密钥?
而且,我不能是唯一一个有这个问题的人吗?从 Visual Studio 部署到 Google Play 应该是一个相当常见的工作流程,但我没有找到遇到此问题的其他任何人(除了这个其他未回答的 SO 问题)。我究竟做错了什么?