dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.17k stars 1.74k forks source link

Crashing on Startup in Release on Physical Devices #14750

Closed TheMattWalker closed 1 year ago

TheMattWalker commented 1 year ago

I am still getting the crash similar to #8928.

I have had to turn AOT off for Android using the following:

<PropertyGroup Condition="$(TargetFramework.Contains('-android')) and $(Configuration)=='Release'">
        <AndroidLinkResources>true</AndroidLinkResources>
        <AndroidLinkMode>None</AndroidLinkMode>
        <RunAOTCompilation>false</RunAOTCompilation>
        <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
</PropertyGroup>

I am able to workaround the issue on iOS by using:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and $(Configuration)=='Release'">
        <MtouchLink>None</MtouchLink>
</PropertyGroup>

It seems to be related to AOT compilation. I also have noticed that there are many .so files missing from my .apk when compared to obj\Release\net7.0-android\android-x\aot\ Update: I have explicitly added dummy code to reference the missing dlls in MauiProgram.cs and the .so files are now showing up in the .apk so there seems to also be an issue with Android picking up all the dependencies. However, I'm still getting the crash and have posted the pertinent log information below.

I am using multiple .NET MAUI Class Libraries as PackageReferences from a private feed. Could there be an issue with AOT and .NET MAUI Class Library references?

This is absolutely ridiculous MAUI released with such a massive issue. I don't even know how #8928 was even closed with this being an issue still and how is no one else running into this?

Also turning AOT off should not be an acceptable workaround. I need AOT working on both Android and iOS.

Using .NET 7.0 with Visual Studio 17.5.4

Eilon commented 1 year ago

@jonathanpeppers - should I transfer to the xamarin-android repo?

jonathanpeppers commented 1 year ago

@TheMattWalker can you share a log of the crash as mentioned here (https://github.com/dotnet/maui/issues/8928#issuecomment-1438648330), or can you share a sample project that has the same issue?

We will probably need to move this to dotnet/runtime, so the Mono team can look into this.

ghost commented 1 year ago

Hi @TheMattWalker. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

TheMattWalker commented 1 year ago

I don't feel comfortable giving out the full log due to the application and device I'm working with, but I'll give you a snippet of the area of concern. Please let me know if this is enough of the log contents or if you need more.

I believe this is the issue:

04-26 09:04:15.643 16393 16393 D Mono : AOT: module Microsoft.Maui.Controls.Compatibility.dll.so is unusable: doesn't match assembly. 04-26 09:04:15.643 16393 16393 D Mono : Assembly found with the filesystem probing logic: 'Microsoft.Maui.Controls.Compatibility'. 04-26 09:04:15.643 16393 16393 D Mono : AOT: module My.App.Name.dll.so is unusable (GUID of dependent assembly Microsoft.Maui.Controls.Compatibility doesn't match (expected '0DD042A3-4E66-4701-BE81-15DDC4F316C7', got 'CB49D7EE-1E4C-4720-9A65-1E318B5A5075')). 04-26 09:04:15.643 16393 16393 E com.my.app.id: * Assertion at /__w/1/s/src/mono/mono/mini/aot-runtime.c:3699, condition `is_ok (error)' not met, function:decode_patch, module 'My.App.Name.dll.so' is unusable (GUID of dependent assembly Microsoft.Maui.Controls.Compatibility doesn't match (expected '0DD042A3-4E66-4701-BE81-15DDC4F316C7', got 'CB49D7EE-1E4C-4720-9A65-1E318B5A5075')). --------- beginning of crash 04-26 09:04:15.643 16393 16393 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 16393 (com.my.app.id), pid 16393 (com.my.app.id)

TheMattWalker commented 1 year ago

Looks like this person is getting a similar issue but there was no response as he posted after the issue was closed. https://github.com/dotnet/maui/issues/8337#issuecomment-1349871117

They are getting the same "'X.dll.so' is unusable (GUID of dependent assembly Microsoft.Maui.Controls.Compatibility doesn't match (expected '922E6FC0-DD06-413F-90A4-780AA1B367E4', got '64BD03AA-54B5-414C-B2F5-AE8BF572941F'))."

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

jonathanpeppers commented 1 year ago

@TheMattWalker the error message above means the AOT images don't match the .dll files in your app.

Given that you run into the same problem with both iOS and Android, are you doing anything custom in the build? Using something that rewrites assemblies? Something like Fody?

Do you have the same issue in a dotnet new maui project?

TheMattWalker commented 1 year ago

@TheMattWalker the error message above means the AOT images don't match the .dll files in your app.

Given that you run into the same problem with both iOS and Android, are you doing anything custom in the build? Using something that rewrites assemblies? Something like Fody?

Do you have the same issue in a dotnet new maui project?

Not doing anything custom in the build just using Visual Studio to build it. I have also tried "dotnet publish -c Release -f net7.0-android" to build it and it has same results.

jonathanpeppers commented 1 year ago

Do you have the same issue in a dotnet new maui project?

TheMattWalker commented 1 year ago

Do you have the same issue in a dotnet new maui project?

No. However, all I have to do is add this to MauiProgram.cs:

builder.UseMauiCompatibility();

and the crash will occur in a dotnet new maui project

image

jonathanpeppers commented 1 year ago

Thanks, I'll try this myself this afternoon. What if you exclude this assembly from trimming?

<ItemGroup>
  <TrimmerRootAssembly Include="Microsoft.Maui.Controls.Compatibility" />
</ItemGroup>

https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-7-0#root-assemblies

TheMattWalker commented 1 year ago

Thanks, I'll try this myself this afternoon. What if you exclude this assembly from trimming?

<ItemGroup>
  <TrimmerRootAssembly Include="Microsoft.Maui.Controls.Compatibility" />
</ItemGroup>

https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-7-0#root-assemblies

That did seem to fix it for the dotnet new maui project.

However still a bit confused as to what is going on. I have another project that was not getting it and compared the csproj files and noticed the one that was getting this issue had

</PropertyGroup>
        <DefaultLanguage>en</DefaultLanguage>
        <Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>

So I removed it and no longer getting this Microsoft.Maui.Controls.Compatibility issue. However, the dotnet new maui project I created as a test didn't have that and I was able to simply add the builder.UseMauiCompatibility(); to reproduce it. So now 2 of my real projects have builder.UseMauiCompatibility(); and no longer getting the Microsoft.Maui.Controls.Compatibility issue in either one.

So not really sure now how to reproduce this Microsoft.Maui.Controls.Compatibility issue but it seems to no longer be an issue for me.

New Issue: (Should I create a new Issue for this?)

I am running into a crash at startup only on Release still on one of my projects but seems to be another issue. I have 2 MAUI projects both referencing a .NET MAUI Class Library, one is referencing the class library as a PackageReference the other is referencing it as a ProjectReference.

In my class library I'm using a ResourceDictionary with this in 2 spots: `

</Setter.Value>`

The MAUI project referencing the MAUI Class Library as PackageReference is getting the following exception only in Release. If I remove the 2 setters using "x:Boolean" I no longer get the following exception and can finally get a working Release build in Android for my project. I also do not get the exception in the project that references the class library as ProjectReference in Release.

04-26 17:12:38.194 23686 23686 I MonoDroid: android.runtime.JavaProxyThrowable: Microsoft.Maui.Controls.Xaml.XamlParseException: Position 935:18. Type Boolean not found in xmlns http://schemas.microsoft.com/winfx/2009/xaml 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[StyleResources](StyleResources view, Type callingType) 04-26 17:12:38.194 23686 23686 I MonoDroid: at MyClassLibrary.GlobalResources.StyleResources.InitializeComponent() 04-26 17:12:38.194 23686 23686 I MonoDroid: at MyClassLibrary.GlobalResources.StyleResources..ctor(ResourceDictionary colorResources) 04-26 17:12:38.194 23686 23686 I MonoDroid: at MyClassLibrary.Themes.Default.DefaultThemeResources..ctor() 04-26 17:12:38.194 23686 23686 I MonoDroid: at MyClassLibrary.ApplyTheme(Theme theme) 04-26 17:12:38.194 23686 23686 I MonoDroid: at MyClassLibrary.set_CurrentTheme(Theme value) 04-26 17:12:38.194 23686 23686 I MonoDroid: at MyClassLibrary.Init(Theme startingTheme) 04-26 17:12:38.194 23686 23686 I MonoDroid: at MyMauiApp..ctor() 04-26 17:12:38.194 23686 23686 I MonoDroid: at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite , RuntimeResolverContext ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite , RuntimeResolverContext ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at System.Collections.Concurrent.ConcurrentDictionary2[[System.Type, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(Type , Func2 ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type , ServiceProviderEngineScope ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider , Type ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredServiceIApplication 04-26 17:12:38.194 23686 23686 I MonoDroid: at Microsoft.Maui.MauiApplication.OnCreate() 04-26 17:12:38.194 23686 23686 I MonoDroid: at Android.App.Application.n_OnCreate(IntPtr , IntPtr ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr ) 04-26 17:12:38.194 23686 23686 I MonoDroid: at crc6488302ad6e9e4df1a.MauiApplication.n_onCreate(Native Method) 04-26 17:12:38.194 23686 23686 I MonoDroid: at crc6488302ad6e9e4df1a.MauiApplication.onCreate(MauiApplication.java:28) 04-26 17:12:38.194 23686 23686 I MonoDroid: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1266) 04-26 17:12:38.194 23686 23686 I MonoDroid: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7632) 04-26 17:12:38.194 23686 23686 I MonoDroid: at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 04-26 17:12:38.194 23686 23686 I MonoDroid: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2402) 04-26 17:12:38.194 23686 23686 I MonoDroid: at android.os.Handler.dispatchMessage(Handler.java:106) 04-26 17:12:38.194 23686 23686 I MonoDroid: at android.os.Looper.loopOnce(Looper.java:226) 04-26 17:12:38.194 23686 23686 I MonoDroid: at android.os.Looper.loop(Looper.java:313) 04-26 17:12:38.194 23686 23686 I MonoDroid: at android.app.ActivityThread.main(ActivityThread.java:8775) 04-26 17:12:38.194 23686 23686 I MonoDroid: at java.lang.reflect.Method.invoke(Native Method) 04-26 17:12:38.194 23686 23686 I MonoDroid: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) 04-26 17:12:38.194 23686 23686 I MonoDroid: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

jonathanpeppers commented 1 year ago

I’d file a new issue for the second problem, a sample project would help. It may be related to: https://github.com/dotnet/maui/pull/14546

TheMattWalker commented 1 year ago

I’d file a new issue for the second problem, a sample project would help. It may be related to: #14546

Thanks for the help!

I have created a new issue here https://github.com/dotnet/maui/issues/14790

TheMattWalker commented 1 year ago

Closing this issue as I'm not sure exactly how to reproduce and no longer getting it.