android: Regression: Runtime errors with IL stripped assemblies

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

Xamarin.Android 12.3

Description

Mono runtime error, app hangs and crashes. See device log output below.

Sample project attached for reference. MSBuild configured to match what I’m using in VS 2019 for app distribution. XamarinAndroidApp.zip

Steps to Reproduce

  1. New Android App (Xamarin) - Blank App
  2. Configure MSBuild for static compilation, IL stripping, and target arm64-v8a
  3. Build and run

Did you find any workaround?

Build with Xamarin.Android 12.0.

Relevant log output

Time	Device Name	Type	PID	Tag	Message
	Sonimtech XP8800	Info	1785	ActivityManager	Process com.companyname.xamarinandroidapp (pid 14562) has died: fore TOP 
	Sonimtech XP8800	Error	14562	mono-rt	
  at Java.Interop.JniRuntime.GetRegisteredRuntime (System.IntPtr invocationPointer) <0x720f10ff0c + 0x0007c> in <4be0212dda1448dbbb5bcb78bcd13cf4>:0 
  at Java.Interop.JniEnvironmentInfo.set_EnvironmentPointer (System.IntPtr value) <0x720f12534c + 0x0008b> in <4be0212dda1448dbbb5bcb78bcd13cf4>:0 
  at Java.Interop.JniRuntime..ctor (Java.Interop.JniRuntime+CreationOptions options) <0x720f110234 + 0x005b7> in <4be0212dda1448dbbb5bcb78bcd13cf4>:0 
  at Android.Runtime.AndroidRuntime..ctor (System.IntPtr jnienv, System.IntPtr vm, System.Boolean allocNewObjectSupported, System.IntPtr classLoader, System.IntPtr classLoader_loadClass, System.Boolean jniAddNativeMethodRegistrationAttributePresent) <0x720f4c15b0 + 0x0008b> in <97754039425649c180140cd9408a4bd2>:0 
  at Android.Runtime.JNIEnv.Initialize (Android.Runtime.JnienvInitializeArgs* args) [0x000f3] in <97754039425649c180140cd9408a4bd2>:0 
	Sonimtech XP8800	Error	14562	mono-rt	
	Sonimtech XP8800	Error	14562	mono-rt	[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in System.Collections.Generic.Dictionary`2<intptr, Java.Interop.JniRuntime>:TryGetValue (intptr,Java.Interop.JniRuntime&): IL_0000: ret       

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 19 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Hi folks @jxbrenner , @gabriel-kozma, add this to your .csproj:

    <AndroidAotAdditionalArguments>hybrid</AndroidAotAdditionalArguments>

@grendello @jonathanpeppers @dellis1972 as far as I can tell, setting <AndroidAotMode>Hybrid</AndroidAotMode> doesn’t actually pass --aot=...,hybrid,... to the mono AOT compiler.

for future reference: I used the following to get extra logging during aot compilation:

    <AndroidAotAdditionalArguments>log-generics,hybrid</AndroidAotAdditionalArguments>
    <AndroidExtraAotOptions>-v</AndroidExtraAotOptions>

which dumps information about added generic instances and also each method that gets compiled.

any updates on this?

@lambdageek would you mind looking at this issue? It seems like mono/mono JIT generating somehow invalid code for generics? Thanks! It happens the very first time we call managed code during startup (we call this method from this code)