dotnet / dotnet/android

See if we can use `$(AndroidAotMode)=full` `MONO_AOT_MODE_FULL`

Open
#9,469 9 comments 1 reaction 1 assignee Assigned to @jonathanpeppers View on GitHub
Area: App Runtime Area: App+Library Build enhancement possibly-stale
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 19h
Merged PRs (30d)
252

Description

### Android framework version

net9.0-android

### Affected platform version

.NET 9 RC 2

### Description

I was trying to enable "full AOT" and disable JIT on Android:
* `dotnet new maui` - remove the other platforms beside Android
* `dotnet build build -c Release -p:AndroidAotMode=full -p:AndroidEnableProfiledAot=false -p:RunAOTCompilation=true -r android-arm64 -bl -t:Run`

This should "AOT everything" and also toggle `MONO_AOT_MODE_FULL` at runtime.

This appears to pass the right flags to the `` task:
![Image](https://github.com/user-attachments/assets/e9a8c078-9c47-4b94-b2ca-02e0846346ee)

And at runtime:
```
10-30 08:58:14.982 9378 9378 D monodroid: Mono AOT mode: full
...
10-30 08:58:14.982 9378 9378 D monodroid: Probing for Mono AOT mode
10-30 08:58:14.982 9378 9378 D monodroid: Enabling AOT mode in Mono
10-30 08:58:14.982 9378 9378 D monodroid: Probing if we should use LLVM
```
https://github.com/dotnet/android/blob/aa668a5c746a7669a145e63efe59d0964093e604/src/native/monodroid/monodroid-glue.cc#L1479

But then the JIT is still used and we crash:
```
10-30 08:58:15.015 9378 9378 F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.ExecutionEngineException: Attempting to JIT compile method '(wrapper other) void Java.Interop.JavaVMInterface:PtrToStructure (intptr,object)' while running in aot-only mode. See https://learn.microsoft.com/xamarin/ios/internals/limitations for more information.
10-30 08:58:15.015 9378 9378 F mono-rt :
10-30 08:58:15.015 9378 9378 F mono-rt : at System.Runtime.InteropServices.Marshal.PtrToStructure[JavaVMInterface](IntPtr )
10-30 08:58:15.015 9378 9378 F mono-rt : at Java.Interop.JniRuntime.CreateInvoker(IntPtr )
10-30 08:58:15.015 9378 9378 F mono-rt : at Java.Interop.JniRuntime..ctor(CreationOptions )
10-30 08:58:15.015 9378 9378 F mono-rt : at Android.Runtime.AndroidRuntime..ctor(IntPtr , IntPtr , IntPtr , IntPtr , Boolean )
10-30 08:58:15.015 9378 9378 F mono-rt : at Android.Runtime.JNIEnvInit.Initialize(JnienvInitializeArgs* )
```
Perhaps it fails on the first generic method?
* https://github.com/dotnet/java-interop/blob/2bdf2bc6932e29d0666db2761e57b163ba9d76fa/src/Java.Interop/Java.Interop/JniRuntime.cs#L272

### Steps to Reproduce

See above.

### Did you find any workaround?

No.

### Relevant log output

[aot-mode-full.txt](https://github.com/user-attachments/files/17574239/aot-mode-full.txt)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.