android: Xamarin.Forms app crashing on .NET 7: Android trimmer undescriptive crashing and insufficient control on trimming

Android application type

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

Affected platform version

VS 2022 17.6.2+, .Net for Android 7+

Description

Enabling “Publish Trimmed” in android projects results in undescriptive crashing that is hard to find the root cause of. There are many trimming warnings that it’s hard to find the actual problem, Trimmer should at least allow you to stop trimming all except for selected assemblies so you can narrow down which ones cause the problem but it still trims and cause runtime crashes even after setting the trimmer to not trim any assembly as follows:

<Target Name="ConfigureTrimming" BeforeTargets="PrepareForILLink"> <ItemGroup> <ManagedAssemblyToLink Condition="true"> <IsTrimmable>false</IsTrimmable> </ManagedAssemblyToLink> </ItemGroup> </Target>

Since Condition="true" and <IsTrimmable>false</IsTrimmable> should disable trimming on all assemblies then this should generate same output like <PublishTrimmed>False</PublishTrimmed> that doesn’t crash at runtime, so then we can at least enable trimming assemblies one by one to find where the problem is. but in reality it still crashes so something still gets trimmed making us unable to use the trimmer or trace its issues.

Strangely same project is published and trimmed on Xamarin android without problems but after migrating to .net for android trimming always causes the app to crash at runtime. Note this is not just about a specific project but the inability of developers to solve trimming crashes and issues generally.

Expected Behavior: Descriptive trimming crash errors and at least ability to disable trimming as above so it wouldn’t trim anything then we can selectively enable trimming assemblies to find where the problem is.

It would be great if we can also export a list of all assemblies that the trimmer would process with their size so at least we can selectively prioritize trimming larger assemblies first. But the priority is to be able to control the trimming starting from trimming nothing then controlling what gets trimmed exactly one by one.

Steps to Reproduce

  1. Enable publish trimmed in project settings
  2. Build and publish If the app that works normally without trimming crashes after trimming there’s no descriptive errors or ability to selectively enable trimming on only selected assemblies.

Did you find any workaround?

No

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 41 (18 by maintainers)

Most upvoted comments

it’s working perfectly but only without trimming. the crashing happens only when we enable trimming. I removed all references to Infragistics packages and can still generate the crash. below project has these packages removed.

AndroidApp24.zip