dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.56k stars 4.54k forks source link

.NET 9: Android application crashes in release mode with Skiasharp #104397

Open daltzctr opened 4 days ago

daltzctr commented 4 days ago

Description

I was directed to submit an issue here by the dotnet android development team. I upgraded my MAUI application to .NET 9 Preview 5 and have occurred release mode crashes whenever initializing a view that contains Skiasharp.

Reproduction Steps

  1. Clone https://github.com/daltzctr/maui-dotnet9-crash (ensure you are using .NET 9)
  2. Run in release mode
  3. Observe crash

Expected behavior

It does not crash

Actual behavior

It crashes

Regression?

Yes. This worked in .NET 8

Known Workarounds

<RunAOTCompilation>False</RunAOTCompilation>

Configuration

.NET SDK:
 Version:           9.0.100-preview.5.24307.3
 Commit:            35b2c21ea6
 Workload version:  9.0.100-manifests.949230c4
 MSBuild version:   17.11.0-preview-24279-02+b963c24ef

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.5.24307.3\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
 [android]
   Installation Source: SDK 9.0.100-preview.5, VS 17.10.35004.147
   Manifest Version:    34.99.0-preview.5.308/9.0.100-preview.5
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.5\microsoft.net.sdk.android\34.99.0-preview.5.308\WorkloadManifest.json
   Install Type:              Msi

 [ios]
   Installation Source: SDK 9.0.100-preview.5, VS 17.10.35004.147
   Manifest Version:    17.2.9639-net9-p5/9.0.100-preview.5
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.5\microsoft.net.sdk.ios\17.2.9639-net9-p5\WorkloadManifest.json
   Install Type:              Msi

 [maccatalyst]
   Installation Source: SDK 9.0.100-preview.5, VS 17.10.35004.147
   Manifest Version:    17.2.9639-net9-p5/9.0.100-preview.5
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.5\microsoft.net.sdk.maccatalyst\17.2.9639-net9-p5\WorkloadManifest.json
   Install Type:              Msi

 [maui-android]
   Installation Source: SDK 9.0.100-preview.5
   Manifest Version:    9.0.0-preview.5.24307.10/9.0.100-preview.5
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.5\microsoft.net.sdk.maui\9.0.0-preview.5.24307.10\WorkloadManifest.json
   Install Type:              Msi

 [maui-ios]
   Installation Source: SDK 9.0.100-preview.5
   Manifest Version:    9.0.0-preview.5.24307.10/9.0.100-preview.5
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.5\microsoft.net.sdk.maui\9.0.0-preview.5.24307.10\WorkloadManifest.json
   Install Type:              Msi

 [maui-maccatalyst]
   Installation Source: SDK 9.0.100-preview.5
   Manifest Version:    9.0.0-preview.5.24307.10/9.0.100-preview.5
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.5\microsoft.net.sdk.maui\9.0.0-preview.5.24307.10\WorkloadManifest.json
   Install Type:              Msi

 [maui-tizen]
   Installation Source: SDK 9.0.100-preview.5
   Manifest Version:    9.0.0-preview.5.24307.10/9.0.100-preview.5
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.5\microsoft.net.sdk.maui\9.0.0-preview.5.24307.10\WorkloadManifest.json
   Install Type:              Msi

 [maui-windows]
   Installation Source: SDK 9.0.100-preview.5, VS 17.10.35004.147
   Manifest Version:    9.0.0-preview.5.24307.10/9.0.100-preview.5
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.5\microsoft.net.sdk.maui\9.0.0-preview.5.24307.10\WorkloadManifest.json
   Install Type:              Msi

Host:
  Version:      9.0.0-preview.5.24306.7
  Architecture: x64
  Commit:       a5cc707d97

.NET SDKs installed:
  8.0.300 [C:\Program Files\dotnet\sdk]
  9.0.100-preview.5.24307.3 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-preview.5.24306.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-preview.5.24306.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.5.24306.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Other information

This is not specific to any MAUI version and only occurs if skiasharp has to be loaded. I have attached some logs that may be useful below. A managed stack trace is not available and I have no other logs besides ones directly shared with Microsoft Staff. Contact @grendello for the detailed log.

07-03 13:33:30.771 11963 11963 D Mono    : Assembly SkiaSharp[0xb400007a87c410c0] added to ALC 'Default'[0xb400007af7c2cf50], ref_count=1
07-03 13:33:30.772 11963 11963 E libsigchain: reverting to SIG_DFL handler for signal 11, ucontext 0x7cc0229e20
07-03 13:33:30.781 11963 11963 E libsigchain:   #00 pc 00006aa4  /apex/com.android.art/lib64/libsigchain.so (LogStack()+164) (BuildId: 438b5b7c0260735178ea56d10fc400a0)
07-03 13:33:30.781 11963 11963 E libsigchain:   #01 pc 000072d4  /apex/com.android.art/lib64/libsigchain.so (art::SignalChain::Handler(int, siginfo*, void*)+1024) (BuildId: 438b5b7c0260735178ea56d10fc400a0)
07-03 13:33:30.781 11963 11963 E libsigchain:   #02 pc 0000088c  [vdso] (+0) (BuildId: )
07-03 13:33:30.781 11963 11963 E libsigchain:   #03 pc 0013c970  /data/app/~~-ShlTI18gqQe9dIMjUUvFw==/com.my_app-KycGcojmE-p1uUYXr1r2YA==/split_config.arm64_v8a.apk (+0) (BuildId: d9a5ed7a80e9461ccb069853eda5e09f2423f875)
lambdageek commented 4 days ago

Discussed with @grendello and tehre's actually two problems here:

  1. Android SDK doesn't deal well with collisions when there's a native library (libSkiaSharp.so) that has a name that matches the base name of a managed assembly (SkiaSharp.dll) because the AOT image lookup may ask for libSkiaSharp.so if it doesn't find its preferred name SkiaSharp.dll.so (I believe this is the first one we ask for). That's https://github.com/dotnet/android/issues/9081

  2. On the runtime side, we need to be more graceful here:

https://github.com/dotnet/runtime/blob/4f96b8f541a62245eb5ca4b643363785cc0d58bf/src/mono/mono/mini/aot-runtime.c#L2100-L2114

if we found sofile, but it doesn't have either the mono_aot_version symbol or the mono_aot_file_info symbol we should set usable = FALSE and fail out gracefully. Instead the first thing we try to do is memcpy from info->aotid even if info might be null.

lambdageek commented 4 days ago

/cc @vitek-karas @steveisok