Skip to content

AndroidStripILAfterAOT likely causing "InvalidProgramException: Invalid IL code in ..." #104156

@tipa

Description

@tipa

Android application type

.NET Android (net7.0-android, net8.0-android, etc.)

Affected platform version

NET 8.0.100

Description

After adding the AndroidStripILAfterAOT=true property to my apps, I started seeing crashes (reported in AppCenter) from my apps in production, e.g.

System.InvalidProgramException: Invalid IL code in System.Drawing.Color:FromArgb (int,int,int,int): method body is empty. 

ColorConverters.FromHex(String hex)
MyApp.Project.get_ColorObject()
MyApp.Project.get_ColorStruct()
MyApp.TimerControlWidget.BuildRemoteViews(Context context, Bundle options)
MyApp.TimerControlWidget.OnUpdate(Context context, AppWidgetManager appWidgetManager, Int32[] appWidgetIds)
Android.Appwidget.AppWidgetProvider.n_OnUpdate_Landroid_content_Context_Landroid_appwidget_AppWidgetManager_arrayI(IntPtr jnienv, IntPtr native__this, IntPtr native_context, IntPtr native_appWidgetManager, IntPtr native_appWidgetIds)
Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_V(_JniMarshal_PPLLL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1, IntPtr p2)

One on of the three crash reports of that app states "Crashed after: 1s", indicating that the app was just cold-booted before crashing.

In another app:

System.InvalidProgramException: Invalid IL code in SQLite.SQLiteConnection:.cctor (): method body is empty.

MyApp.DatabaseHelper.GetConnection()
MyApp.DatabaseHelper.get_Db()
MyApp.DatabaseHelper.GetEntry(DateTime date)
MyApp.StackRemoteViewsFactory.GetViewAt(Int32 position)
Android.Widget.RemoteViewsService.IRemoteViewsFactoryInvoker.n_GetViewAt_I(IntPtr jnienv, IntPtr native__this, Int32 position)
Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPI_L(_JniMarshal_PPI_L callback, IntPtr jnienv, IntPtr klazz, Int32 p0)

All 4/4 crash reports I got for that app state "Crashed after: 0s".

All seven crash reports were sent from (different) Samsung devices.
All seven crash reports originated from the apps widgets.

Steps to Reproduce

My .csproj look something like this:

  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <AndroidUseDefaultAotProfile>False</AndroidUseDefaultAotProfile>
    <AndroidEnableProfiledAot>True</AndroidEnableProfiledAot>
    <AndroidStripILAfterAOT>True</AndroidStripILAfterAOT>
    <AndroidLinkTool>r8</AndroidLinkTool>
    <TrimMode>full</TrimMode>
  </PropertyGroup>
  <ItemGroup>
    <AndroidAotProfile Include="custom.aprof" />
  </ItemGroup>

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions