这似乎是由于从 JDK 1.6 切换到 JDK 1.7 造成的。我建议不要坚持使用 JDK 1.6(在某些情况下不是一个选项),而是基于http://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics创建一个用于创建签名和对齐 apk 的小脚本/publishing_an_application/part_1_-_preparing_an_application_for_release/
# First clean the Release target.
msbuild.exe HelloWorld.csproj /p:Configuration=Release /t:Clean
# Now build the project, using the Release target.
msbuild.exe HelloWorld.csproj /p:Configuration=Release /t:PackageForAndroid
# At this point there is only the unsigned APK - sign it.
# The script will pause here as jarsigner prompts for the password.
# It is possible to provide they keystore password for jarsigner.exe by adding an extra command line parameter -storepass, for example
# -storepass <MY_SECRET_PASSWORD>
# If this script is to be checked in to source code control then it is not recommended to include the password as part of this script.
& 'C:\Program Files\Java\jdk1.6.0_24\bin\jarsigner.exe' -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ./xample.keystore -signedjar ./bin/Release/mono.samples.helloworld-signed.apk ./bin/Release/mono.samples.helloworld.apk publishingdoc
# Now zipalign it. The -v parameter tells zipalign to verify the APK afterwards.
& 'C:\Program Files\Android\android-sdk\tools\zipalign.exe' -f -v 4 ./bin/Release/mono.samples.helloworld-signed.apk ./helloworld.apk
重要的部分是使用-sigalg SHA1withRSA -digestalg SHA1
强制 JDK 1.7 使用预期摘要算法的参数(而不是 SHA-256,这似乎是 JDK 1.7 中的默认值,并非所有 Android 版本都接受)。
请注意,您可以使用以下命令找到 msbuild 位置
$dotNetVersion = "4.0"
$regKey = "HKLM:\software\Microsoft\MSBuild\ToolsVersions\$dotNetVersion"
$regProperty = "MSBuildToolsPath"
$msbuildExe = join-path -path (Get-ItemProperty $regKey).$regProperty -childpath "msbuild.exe"