maui icon indicating copy to clipboard operation
maui copied to clipboard

[.NET 10] AndroidLinkMode=SdkOnly crashes on startup with "only_unmanaged_callers_only" assertion (icall.c:6261)

Open yBouzeliffa opened this issue 11 months ago • 5 comments

Description

Summary

A blank .NET MAUI app crashes immediately on startup when built in Release mode with AndroidLinkMode=SdkOnly on .NET 10. The app works perfectly in Debug mode and in Release mode with AndroidLinkMode=None.

Environment

  • .NET SDK: 10.0.100
  • MAUI: 10.0.11
  • Visual Studio 2022 (latest)
  • Target: net10.0-android
  • Test device: Physical Android device (API 34)
  • Windows 11

Error

Assertion at /__w/1/s/src/mono/mono/metadata/icall.c:6261, condition `only_unmanaged_callers_only' not met

The crash occurs during native library initialization, specifically when loading libSystem.Security.Cryptography.Native.Android.so.

Expected Behavior

The app should start normally with AndroidLinkMode=SdkOnly, as this is the documented default for Release builds.

Actual Behavior

The app crashes immediately on startup before any user code executes.

Workaround

Setting AndroidLinkMode=None allows the app to run, but this defeats the purpose of linking and results in larger APK sizes.

Related Issues

  • #7876 (similar error but was closed as "clean rebuild" - does not apply here as this reproduces on a brand new project)
  • #10063 (AndroidLinkMode=None crash on .NET 9 - different issue)

Steps to Reproduce

  1. Create a new .NET MAUI app:

  2. Add the following to the .csproj file:

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)'=='Release|net10.0-android'">
    <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
    <AndroidLinkMode>SdkOnly</AndroidLinkMode>
    <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
    <AndroidPackageFormat>apk</AndroidPackageFormat>
    <PublishTrimmed>false</PublishTrimmed>
    <RunAOTCompilation>false</RunAOTCompilation>
    <AndroidEnableMarshalMethods>false</AndroidEnableMarshalMethods>
</PropertyGroup>

3.Build and publish in Release mode:
   dotnet publish -f net10.0-android -c Release

4.Install the APK on a physical Android device

5.Launch the app → Crash on startup

6.Change AndroidLinkMode to None and repeat steps 3-5 → App works


### Link to public reproduction project repository

_No response_

### Version with bug

10.0.11

### Is this a regression from previous behavior?

Not sure, did not test other versions

### Last version that worked well

Unknown/Other

### Affected platforms

Android

### Affected platform versions

Android 5.0+ (API 21+) - tested on Android 14 (API 34) physical device

### Did you find any workaround?

_No response_

### Relevant log output

```shell

yBouzeliffa avatar Dec 07 '25 10:12 yBouzeliffa

I've been getting similar build issues after upgrading to .NET 10 on Android, the workaround I found is to delete bin/obj folders with VS closed (Clean or Rebuild does not work) and then use dotnet publish. For me, seem like something is getting cached and not properly reused on the next Android Build.

Superxwolf avatar Dec 07 '25 17:12 Superxwolf

thanks you for the quick response. i figure out that dotnet publish without any configuration on csproj work. It only create crash on app startup when i put optimisation on csproj like

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)'=='Release|net10.0-android'"> <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime> <AndroidLinkMode>SdkOnly</AndroidLinkMode> <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk> <AndroidPackageFormat>apk</AndroidPackageFormat> <PublishTrimmed>false</PublishTrimmed> <RunAOTCompilation>false</RunAOTCompilation> <AndroidEnableMarshalMethods>false</AndroidEnableMarshalMethods> </PropertyGroup>

yBouzeliffa avatar Dec 07 '25 18:12 yBouzeliffa

This issue has been validated in Visual Studio 18.0.0 with MAUI versions 10.0.11. It can be reproducible on Android 11 Physical device with AndroidLinkMode(SdkOnly)

Image

Ahamed-Ali avatar Dec 08 '25 13:12 Ahamed-Ali

Why isn't this documented as a "Known Issue" somewhere? It's pretty serious not being able to create an Android Release build (one that you could reasonably publish to your users).

AntHillOracle avatar Dec 23 '25 22:12 AntHillOracle

any updates? because i get simillar problem. When run debug in Android running well but in release mode crash.

raselldev avatar Jan 22 '26 08:01 raselldev