iOS Distribution - .NET MAUI
iOS App crashing instantly in Release mode
This is a classic one. Almost every time I update my nuget packages since a longer time I run into that issue.
Reason: It is in 99.9% of occurences caused by the aot-compilation (ahead of time) for iOS in MAUI. Some nuget packages don’t always support the necessary aot-stuff and instead are jit-compiled (just in time). It can happen from my experience also sometimes tho if you use generics etc.
Fix: There are several ways to fix this issue, which all have its up and downsides, so lets get started.
#1: Enabling the interpreter
The upside of that is that it is a one fits all method. If you need to release quickly this is in my opinion the way to go. With this you enable jit compilation for iOS making that kind of problems vanish.
The problem with that is that you take a major hit on performance for iOS. For me at least this is not optimal making it only a “emergency solution”
Here is how you do it:
- Go into your .csproj file
- Paste the following code
- Rebuild
<PropertyGroup Condition=“$(TargetFramework.Contains(‘-ios’)) and ‘$(Configuration)’ == ‘Release'”> <UseInterpreter>true</UseInterpreter> </PropertyGroup>
#2: Enabling the MtouchInterpreter
The upside of that is that for me at least it is not as big as a performance hit as with the interpreter. I don’t know if thats accurate but at least from my experience it feels better.
The problem is it won’t help with every issue regarding aot. For me I use this especially with the LiteDB nuget package. Here it works fine but I also ran into cases, where that doesn’t help at all. Making it for me also not optimal.
Here is how you do it:
- Go into your .csproj file
- Paste the following code
- Rebuild
<PropertyGroup Condition=“$(TargetFramework.Contains(‘-ios’)) and ‘$(Configuration)’ == ‘Release'”> <MtouchInterpreter>-all</MtouchInterpreter> </PropertyGroup>
Btw here is the official documentation by Microsoft: Mono interpreter on iOS and Mac Catalyst – .NET MAUI | Microsoft Learn
Was that helpful so far?
The consider subscribing to my newsletter, where I also talk about .NET MAUI in general, self-improvement and building stuff 🙂
#3: Searching for the nuget package, which causes the issues
Problem first here: it takes more time than the other methods. But if you know how to do this efficiently it will help you get the best performance for your app.
Like stated before I had this issue with the whole aot stuff several times at that point and developed the perfect strategy to deal with it.
Here is how you do it:
- Connect your iPhone where you installed the app to your Mac via cable
- Open the app “Console” on your Mac Console User Guide for Mac – Apple Support (SG)
- Choose your phone and click on start stream
- Open the app that has the problem
- Search for the error in the Mac “Console” app -> There is stated, which nuget causes the aot problems as seen in the screenshot below
- Then downgrade or upgrade it to a version where it works again 🙂