MAUI apps with .NET 8 don't work on android

paro_ricc 0 Reputation points
2024-03-28T16:36:19.4466667+00:00

I'm trying to execute on android the demo app created by visual studio when you create a new MAUI .NET 8 project but I encountered different problems in debug and release mode.

Visual Studio version : 17.9.5


When I try to run the app in debug it crashes at startup with no useful errors:

Timestamp: 2024-03-28 14:58:29.913314700+0000

Process uptime: 4s

Cmdline: com.companyname.testnet8

pid: 11257, tid: 11257, name: nyname.testnet8 >>> com.companyname.testnet8 <<<

uid: 10173

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)


Instead when I try to compile it in release mode I receive these errors:

without any changes:

Severity Code Description Project File Line Suppression State

Error IL1012 IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink TestNet8 C:\Users\Sviluppo2\Desktop\Test\TestNet8\ILLink 1

Severity Code Description Project File Line Suppression State

Error NETSDK1144 Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. TestNet8 C:\Nuget\microsoft.net.illink.tasks\8.0.3\build\Microsoft.NET.ILLink.targets 87  

Build started at 09:11...

1>------ Build started: Project: TestNet8, Configuration: Release Any CPU ------

1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.

1>TestNet8 -> C:\Users\Sviluppo2\Desktop\Test\TestNet8\bin\Release\net8.0-android\TestNet8.dll

1>Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink

1>Optimizing assemblies for size. This process might take a while.

1>Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink

1>Optimizing assemblies for size. This process might take a while.

1>Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink

1>Optimizing assemblies for size. This process might take a while.

1>Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink

1>Optimizing assemblies for size. This process might take a while.

1>ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink

1>Fatal error in IL Linker

1>Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.

1> at Mono.Cecil.Cil.CodeReader.ReadSequencePoints()

1> at Mono.Cecil.Cil.CodeReader.ReadMethodBody()

1> at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)

1> at Mono.Cecil.ModuleDefinition.Read[TItem,TRet]

1> at Mono.Cecil.MethodDefinition.get_Body()

1> at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason, MessageOrigin& origin)

1> at Mono.Linker.Steps.MarkStep.ProcessQueue()

1> at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()

1> at Mono.Linker.Steps.MarkStep.Process()

1> at Mono.Linker.Steps.MarkStep.Process(LinkContext context)

1> at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)

1> at Mono.Linker.Pipeline.Process(LinkContext context)

1> at Mono.Linker.Driver.Run(ILogger customLogger)

1> at Mono.Linker.Driver.Main(String[] args)

1>ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink

1>Fatal error in IL Linker

1>Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.

1> at Mono.Cecil.Cil.CodeReader.GetInstruction(Collection`1 instructions, Int32 offset)

1> at Mono.Cecil.Cil.CodeReader.ReadSequencePoints()

1> at Mono.Cecil.Cil.CodeReader.ReadMethodBody()

1> at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)

1> at Mono.Cecil.ModuleDefinition.Read[TItem,TRet]

1> at Mono.Cecil.MethodDefinition.get_Body()

1> at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason, MessageOrigin& origin)

1> at Mono.Linker.Steps.MarkStep.ProcessQueue()

1> at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()

1> at Mono.Linker.Steps.MarkStep.Process()

1> at Mono.Linker.Steps.MarkStep.Process(LinkContext context)

1> at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)

1> at Mono.Linker.Pipeline.Process(LinkContext context)

1> at Mono.Linker.Driver.Run(ILogger customLogger)

1> at Mono.Linker.Driver.Main(String[] args)

1>ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink

1>Fatal error in IL Linker

1>Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.

1> at Mono.Cecil.Cil.CodeReader.GetInstruction(Collection`1 instructions, Int32 offset)

1> at Mono.Cecil.Cil.CodeReader.ReadSequencePoints()

1> at Mono.Cecil.Cil.CodeReader.ReadMethodBody()

1> at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)

1> at Mono.Cecil.ModuleDefinition.Read[TItem,TRet]

1> at Mono.Cecil.MethodDefinition.get_Body()

1> at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason, MessageOrigin& origin)

1> at Mono.Linker.Steps.MarkStep.ProcessQueue()

1> at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()

1> at Mono.Linker.Steps.MarkStep.Process()

1> at Mono.Linker.Steps.MarkStep.Process(LinkContext context)

1> at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)

1> at Mono.Linker.Pipeline.Process(LinkContext context)

1> at Mono.Linker.Driver.Run(ILogger customLogger)

1> at Mono.Linker.Driver.Main(String[] args)

1>ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink

1>Fatal error in IL Linker

1>Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.

1> at Mono.Cecil.Cil.CodeReader.GetInstruction(Collection`1 instructions, Int32 offset)

1> at Mono.Cecil.Cil.CodeReader.ReadSequencePoints()

1> at Mono.Cecil.Cil.CodeReader.ReadMethodBody()

1> at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)

1> at Mono.Cecil.ModuleDefinition.Read[TItem,TRet]

1> at Mono.Cecil.MethodDefinition.get_Body()

1> at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason, MessageOrigin& origin)

1> at Mono.Linker.Steps.MarkStep.ProcessQueue()

1> at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()

1> at Mono.Linker.Steps.MarkStep.Process()

1> at Mono.Linker.Steps.MarkStep.Process(LinkContext context)

1> at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)

1> at Mono.Linker.Pipeline.Process(LinkContext context)

1> at Mono.Linker.Driver.Run(ILogger customLogger)

1> at Mono.Linker.Driver.Main(String[] args)

1>C:\Nuget\microsoft.net.illink.tasks\8.0.3\build\Microsoft.NET.ILLink.targets(87,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.

1>Done building project "TestNet8.csproj" -- FAILED.

1>C:\Nuget\microsoft.net.illink.tasks\8.0.3\build\Microsoft.NET.ILLink.targets(87,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.

1>Done building project "TestNet8.csproj" -- FAILED.

1>C:\Nuget\microsoft.net.illink.tasks\8.0.3\build\Microsoft.NET.ILLink.targets(87,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.

1>Done building project "TestNet8.csproj" -- FAILED.

1>C:\Nuget\microsoft.net.illink.tasks\8.0.3\build\Microsoft.NET.ILLink.targets(87,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.

1>Done building project "TestNet8.csproj" -- FAILED.

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

========== Build completed at 09:12 and took 43,740 seconds ==========

========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

========== Deploy completed at 09:12 and took 43,742 seconds ==========

set PublishTrimmed as false:

Severity Code Description Project File Line Suppression State

Error XA1030 The 'RunAOTCompilation' MSBuild property is only supported when trimming is enabled. Edit the project file in a text editor to set 'PublishTrimmed' to 'true' for this build configuration. TestNet8 C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.85\tools\Xamarin.Android.Common.targets 552

Build started at 09:14...

1>------ Build started: Project: TestNet8, Configuration: Release Any CPU ------

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.85\tools\Xamarin.Android.Common.targets(552,3): error XA1030: The 'RunAOTCompilation' MSBuild property is only supported when trimming is enabled. Edit the project file in a text editor to set 'PublishTrimmed' to 'true' for this build configuration.

1>Done building project "TestNet8.csproj" -- FAILED.

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

========== Build completed at 09:14 and took 00,531 seconds ==========

========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

========== Deploy completed at 09:14 and took 00,531 seconds ==========

 

set PublishTrimmed and RunAOTCompilation as false:

Severity Code Description Project File Line Suppression State

Error XALNS7009 System.InvalidOperationException: Sequence contains no elements

at System.Linq.Enumerable.Last[TSource]

at MonoDroid.Tuner.AddKeepAlivesStep.AddKeepAlives(TypeDefinition type)

at MonoDroid.Tuner.AddKeepAlivesStep.AddKeepAlives(AssemblyDefinition assembly)

at Xamarin.Android.Tasks.LinkAssembliesNoShrink.RunTask()

at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 TestNet8 C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.85\tools\Xamarin.Android.Common.targets 1482

Build started at 09:15...

1>------ Build started: Project: TestNet8, Configuration: Release Any CPU ------

1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.

1>TestNet8 -> C:\Users\Sviluppo2\Desktop\Test\TestNet8\bin\Release\net8.0-android\TestNet8.dll

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.85\tools\Xamarin.Android.Common.targets(1482,3): error XALNS7009: System.InvalidOperationException: Sequence contains no elements

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.85\tools\Xamarin.Android.Common.targets(1482,3): error XALNS7009: at System.Linq.Enumerable.Last[TSource]

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.85\tools\Xamarin.Android.Common.targets(1482,3): error XALNS7009: at MonoDroid.Tuner.AddKeepAlivesStep.AddKeepAlives(TypeDefinition type)

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.85\tools\Xamarin.Android.Common.targets(1482,3): error XALNS7009: at MonoDroid.Tuner.AddKeepAlivesStep.AddKeepAlives(AssemblyDefinition assembly)

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.85\tools\Xamarin.Android.Common.targets(1482,3): error XALNS7009: at Xamarin.Android.Tasks.LinkAssembliesNoShrink.RunTask()

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.85\tools\Xamarin.Android.Common.targets(1482,3): error XALNS7009: at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

1>Done building project "TestNet8.csproj" -- FAILED.

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

========== Build completed at 09:15 and took 10,250 seconds ==========

========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

========== Deploy completed at 09:15 and took 10,250 seconds ==========


I tried different phisical devices and emulators with the exact same results.

I hope someone could suggest me more tests to do to understand better where is the problem. I already tried to reinstall visual studio in all the ways possible dut nothing changed.

Ask me any questions and I will try to answer as best I can.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,870 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,546 Reputation points Microsoft Vendor
    2024-03-29T02:39:27.3233333+00:00

    Hello,

    According to the error code NETSDK1144, the cause and solution of the error have been given in the official .Net documentation, please refer to .NET SDK error list for more details.

    NETSDK1144 Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.