Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
VS 2022 17.4.3
Description
The .net 6 template app will crash if you modify it to limit RID support to android-arm and android-x64 when deploying to an android-arm64 device. I have an app that has 32-bit ARM .so files that I reference, but does not have 64-bit versions of the same files for ARM. I do have 32-bit and 64-bit versions for Intel.
For legacy Xamarin Android I could specify <AndroidSupportedAbis>armeabi-v7a;x86_64</AndroidSupportedAbis>. For net6.0, specifying <RuntimeIdentifiers>android-arm;android-x64</RuntimeIdentifiers> results in an app that crashes with:
12-23 14:48:24.156 24884 24884 F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.OverflowException: Arithmetic operation resulted in an overflow.
12-23 14:48:24.156 24884 24884 F mono-rt : at System.Runtime.InteropServices.Marshal.ReadIntPtr(IntPtr ptr, Int32 ofs)
12-23 14:48:24.156 24884 24884 F mono-rt : at System.Runtime.InteropServices.Marshal.ReadIntPtr(IntPtr ptr)
12-23 14:48:24.156 24884 24884 F mono-rt : at Java.Interop.JniRuntime.CreateInvoker(IntPtr handle)
12-23 14:48:24.156 24884 24884 F mono-rt : at Java.Interop.JniRuntime..ctor(CreationOptions options)
12-23 14:48:24.156 24884 24884 F mono-rt : at Android.Runtime.AndroidRuntime..ctor(IntPtr jnienv, IntPtr vm, Boolean allocNewObjectSupported, IntPtr classLoader, IntPtr classLoader_loadClass, Boolean jniAddNativeMethodRegistrationAttributePresent)
12-23 14:48:24.156 24884 24884 F mono-rt : at Android.Runtime.JNIEnv.Initialize(JnienvInitializeArgs* args)
Steps to Reproduce
From a command prompt with VS 2022 17.4.3:
- dotnet new android
- Modify .csproj to target net6.0-android (rather than net7.0-android).
- Modify .csproj to contain
<RuntimeIdentifiers>android-arm;android-x64</RuntimeIdentifiers>
- dotnet build -t:Run -f net6.0-android
I expect the app to launch and display "Hello Android!". Instead, the app launches to a white screen with no text.
Did you find any workaround?
Uninstalling the app from the Android device, then modifying the app to target .net7.0-android works as expected when building and running for net7.0-android.
It is a costly workaround - my app requires quite a bit of work to update to .net7.0 due to Android SDK requirement changes for MAUI.
Relevant log output
12-23 14:48:24.156 24884 24884 F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.OverflowException: Arithmetic operation resulted in an overflow.
12-23 14:48:24.156 24884 24884 F mono-rt : at System.Runtime.InteropServices.Marshal.ReadIntPtr(IntPtr ptr, Int32 ofs)
12-23 14:48:24.156 24884 24884 F mono-rt : at System.Runtime.InteropServices.Marshal.ReadIntPtr(IntPtr ptr)
12-23 14:48:24.156 24884 24884 F mono-rt : at Java.Interop.JniRuntime.CreateInvoker(IntPtr handle)
12-23 14:48:24.156 24884 24884 F mono-rt : at Java.Interop.JniRuntime..ctor(CreationOptions options)
12-23 14:48:24.156 24884 24884 F mono-rt : at Android.Runtime.AndroidRuntime..ctor(IntPtr jnienv, IntPtr vm, Boolean allocNewObjectSupported, IntPtr classLoader, IntPtr classLoader_loadClass, Boolean jniAddNativeMethodRegistrationAttributePresent)
12-23 14:48:24.156 24884 24884 F mono-rt : at Android.Runtime.JNIEnv.Initialize(JnienvInitializeArgs* args)
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
VS 2022 17.4.3
Description
The .net 6 template app will crash if you modify it to limit RID support to android-arm and android-x64 when deploying to an android-arm64 device. I have an app that has 32-bit ARM .so files that I reference, but does not have 64-bit versions of the same files for ARM. I do have 32-bit and 64-bit versions for Intel.
For legacy Xamarin Android I could specify
<AndroidSupportedAbis>armeabi-v7a;x86_64</AndroidSupportedAbis>. For net6.0, specifying<RuntimeIdentifiers>android-arm;android-x64</RuntimeIdentifiers>results in an app that crashes with:Steps to Reproduce
From a command prompt with VS 2022 17.4.3:
<RuntimeIdentifiers>android-arm;android-x64</RuntimeIdentifiers>I expect the app to launch and display "Hello Android!". Instead, the app launches to a white screen with no text.
Did you find any workaround?
Uninstalling the app from the Android device, then modifying the app to target .net7.0-android works as expected when building and running for net7.0-android.
It is a costly workaround - my app requires quite a bit of work to update to .net7.0 due to Android SDK requirement changes for MAUI.
Relevant log output