Xamarin 应用程序 - 无法部署到 Android 11 模拟器 [英] Xamarin App - Can't deploy to Android 11 emulator

查看:37
本文介绍了Xamarin 应用程序 - 无法部署到 Android 11 模拟器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法部署到 Android 11 模拟器.(我可以部署到 Android 10 模拟器)

Can't deploy to Android 11 emulator. (I can deploy to Android 10 emulator)

ADB0010:  Deployment failed
Mono.AndroidTools.InstallFailedException: The package was not properly signed (NO_CERTIFICATES).
   at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
   at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass97_0.<InstallPackage>b__0(Task`1 t)
   at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at AndroidDeviceExtensions.<PushAndInstallPackage>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Xamarin.AndroidTools.AndroidDeploySession.<InstallPackage>d__116.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Xamarin.AndroidTools.AndroidDeploySession.<RunAsync>d__110.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.AndroidTools.AndroidDeploySession.<RunLoggedAsync>d__108.MoveNext()

这是一个调试版本,所以我没有明确签署它.

This is a debug build, so I'm not explicitly signing it.

但我注意到它无论如何都会使用 androiddebugkey 自动签名:

But I notice that it's automatically being signed anyway with an androiddebugkey:

C:\Program Files\Android\Jdk\microsoft_dist_openjdk_1.8.0.25\bin\jarsigner.exe -keystore "C:\Users\$USERNAME$\AppData\Local\Xamarin\Mono for Android\debug.keystore" -storepass android -keypass android -digestalg SHA-256 -sigalg SHA256withRSA -signedjar bin\Debug\$UNSIGNEDAPKNAME$.apk $PATHTOAPK$.apk androiddebugkey 

如果 debug.keystore 因某种原因过时(我的时间戳为 2018-03-26),我将其删除并通过构建重新生成.(具有合理的大小差异),但我仍然收到 Mono.AndroidTools.InstallFailedException: The package was not correctly signed (NO_CERTIFICATES)." 错误.

In case debug.keystore, was somehow out of date, (mine was timestamped 2018-03-26), I removed it and it got regenerated by the build. (with reasonable sized differences), But I still received the "Mono.AndroidTools.InstallFailedException: The package was not properly signed (NO_CERTIFICATES)." error.

我尝试过清理和重建.我的目标是 Android 11.0(API 级别 30 -R)

I've tried cleaning and rebuilding. I'm targeting Android 11.0 (API Level 30 -R)

更新:

当我手动尝试使用 adb 进行安装时,我收到了更多信息:

I received a little more information when I manually attempting to installing with adb:

adb -e install $myapp$.apk

... 
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Scanning Failed.: No signature found in package of version 2 or newer for package $PACKAGE$]

推荐答案

现在需要 APK 签名方案 v2 :

"目前仅使用 APK 签名方案 v1 签名的面向 Android 11(API 级别 30)的应用现在也必须使用 APK 签名方案 v2 或更高版本进行签名.用户无法在运行 Android 11 的设备上安装或更新仅使用 APK 签名方案 v1 签名的应用."

"Apps that target Android 11 (API level 30) that are currently only signed using APK Signature Scheme v1 must now also be signed using APK Signature Scheme v2 or higher. Users can't install or update apps that are only signed with APK Signature Scheme v1 on devices that run Android 11."

在定位 android 11 时,使用 jarsigner.exe 签名不够好.使用 apksigner 签名,包括 v2 方案.

Signing with jarsigner.exe isn't good enough, when Targeting android 11. Signing with apksigner, includes the v2 scheme.

例如这样的签名,使用相同的 debug.keystore 允许将 apk 安装在 android 11 上.

For example signing like this, using the same debug.keystore allows the apk to be installed on android 11.

"C:\Program Files (x86)\Android\android-sdk\build-tools\30.0.2\apksigner.bat" sign -ks "C:\Users\%USERNAME%\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass "pass:android" $APKNAME$.apk

通过 csproj 文件切换到 apksigner

通过将 true 添加到 csproj 文件,可以将 Xamarin 版本切换到 apksigner.(我还没有找到在 UI 中执行此操作的方法.也许这是一个实验性功能?)

Switching to apksigner via csproj file

The Xamarin build can be switched to apksigner, by adding <AndroidUseApkSigner>true</AndroidUseApkSigner> to the csproj file. (I haven't found a way to do this in the UI. perhaps this is an experimental feature?)

您必须使用相对较新的 BuildTools 版本来执行此操作,例如:

You must be using a relatively new BuildTools version to do this eg:

<AndroidSdkBuildToolsVersion>28.0.3</AndroidSdkBuildToolsVersion>

现在构建对 apk 的签名如下:

Now the build signs the apk like this:

C:\Program Files\Android\Jdk\microsoft_dist_openjdk_1.8.0.25\bin\java.exe -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.3\lib\apksigner.jar" sign --ks "C:\Users\%USERNAME%\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 22 --max-sdk-version 30  $APKNAME$ 

这篇关于Xamarin 应用程序 - 无法部署到 Android 11 模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆