Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] add //manifest/queries for API 30 (dotn…
…et#4846) Context: https://developer.android.com/preview/privacy/package-visibility#package-name If using Fast Deployment with an API 30 device or emulator and `AndroidManifest.xml` sets `//uses-sdk/@android:targetSdkVersion`=30, the app will crash on startup with: I AppsFilter: interaction: PackageSetting{f346c3d com.companyname.app72/10152} -> PackageSetting{67adc32 Mono.Android.Platform.ApiLevel_30/10151} BLOCKED … E AndroidRuntime: java.lang.RuntimeException: Unable to get provider mono.MonoRuntimeProvider: java.lang.RuntimeException: Unable to find application Mono.Android.Platform.ApiLevel_30! E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:7135) E AndroidRuntime: at android.app.ActivityThread.installContentProviders(ActivityThread.java:6675) E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6592) E AndroidRuntime: at android.app.ActivityThread.access$1300(ActivityThread.java:233) E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896) E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) E AndroidRuntime: at android.os.Looper.loop(Looper.java:223) E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7523) E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941) E AndroidRuntime: Caused by: java.lang.RuntimeException: Unable to find application Mono.Android.Platform.ApiLevel_30! E AndroidRuntime: at mono.MonoRuntimeProvider.attachInfo(MonoRuntimeProvider.java:38) E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:7130) E AndroidRuntime: ... 10 more E AndroidRuntime: Caused by: android.content.pm.PackageManager$NameNotFoundException: Mono.Android.Platform.ApiLevel_30 E AndroidRuntime: at android.app.ApplicationPackageManager.getApplicationInfoAsUser(ApplicationPackageManager.java:419) E AndroidRuntime: at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:408) E AndroidRuntime: at mono.MonoRuntimeProvider.attachInfo(MonoRuntimeProvider.java:35) E AndroidRuntime: ... 11 more On Android 11, any calls to [`PackageManager.getApplicationInfo()`][0], as is done in [`MonoRuntimeProvider.java`][1], will now throw `PackageManager.NameNotFoundException` *unless* the requested package name is explicitly listed in the new (and undocumented) `/manifest/queries/package/@android:name` attribute: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.xamarin.android.helloworld"> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" /> … <queries> <package android:name="Mono.Android.Platform.ApiLevel_30" /> <package android:name="Mono.Android.DebugRuntime" /> </queries> </manifest> Update `ManifestDocument.cs` to generate the appropriate `//queries/package` elements when: * `$(AndroidUseSharedRuntime)` is True * `android:targetSdkVersion` is 30 or higher The only problem with the new `<queries/>` element is that older versions of `aapt2` will fail with: error APT2263: unexpected element <queries> found in <manifest>. Luckily in cbdb5d1, we bumped to a version of `aapt2` that works. `aapt` appears to already work; it must not do any validation against new XML element names. I added a test for this scenario as well. Finally, bump to manifest-merger 27.0.0 (2c6f5cd), as that is also required to fully support the new `<queries/>` element. [0]: https://developer.android.com/reference/android/content/pm/PackageManager#getApplicationInfo(java.lang.String,%20int) [1]: https://github.com/xamarin/xamarin-android/blob/17db4dc1e8ba6438fc02fdbb0e2fbe6c16fb4b58/src/Xamarin.Android.Build.Tasks/Resources/MonoRuntimeProvider.Shared.java#L35
- Loading branch information