You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Context: #9630
Context: #9716
Context: dotnet/java-interop@e288589@jonathanpeppers attempted to prototype MAUI startup in a NativeAOT
environment, which promptly crashes similar to:
E AndroidRuntime: net.dot.jni.internal.JavaProxyThrowable: System.DllNotFoundException: DllNotFound_Linux, xa-internal-api,
E AndroidRuntime: dlopen failed: library "xa-internal-api" not found
E AndroidRuntime: dlopen failed: library "libxa-internal-api" not found
E AndroidRuntime:
E AndroidRuntime: at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x47
E AndroidRuntime: at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0xe2
E AndroidRuntime: at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
E AndroidRuntime: at Android.Runtime.RuntimeNativeMethods.monodroid_TypeManager_get_java_class_name(IntPtr) + 0x22
E AndroidRuntime: at Java.Interop.TypeManager.GetClassName(IntPtr) + 0xe
E AndroidRuntime: at Java.Interop.TypeManager.CreateInstance(IntPtr, JniHandleOwnership, Type) + 0x69
E AndroidRuntime: at Java.Lang.Object._GetObject[T](IntPtr, JniHandleOwnership) + 0x4e
E AndroidRuntime: at Android.App.Application.n_OnCreate(IntPtr jnienv, IntPtr native__this) + 0x89
E AndroidRuntime: at my.MainApplication.n_onCreate(Native Method)
E AndroidRuntime: at my.MainApplication.onCreate(MainApplication.java:24)
E AndroidRuntime: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1182)
E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6460)
E AndroidRuntime: at android.app.ActivityThread.access$1300(ActivityThread.java:219)
E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
E AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7356)
E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
because:
1. MAUI apps provide an `Android.App.Application` sublass, and
2. [`Application` is "special"][0], and
3. When `Java.Lang.Object.GetObject<T>()` is hit for an instance
which doesn't already have an instance mapping -- i.e.
`Object.PeekObject()` returns `null` -- then we'd hit
`TypeManager.CreateInstance()`, which is a codepath full of
P/Invokes, and P/Invokes don't currently work on NativeAOT [^1].
The solution is to partially resuscitate PR #9630, but this time have
`Java.Lang.Object.GetObject<T>()` call
`Java.Interop.JniRuntime.JniValueManager.GetPeer()` instead of
`Java.Interop.JniRuntime.JniValueManager.GetValue()`; see also
dotnet/java-interop@e288589d.
This allows `Application` subclasses to be used (along with other
build system changes present in #9716).
This also cleans up a few things if `Java.Lang.Object` introduces an
internal `DynamicallyAccessedMemberTypes Constructors` field.
[0]: https://learn.microsoft.com/en-us/previous-versions/xamarin/android/internals/architecture#java-activation
[^1]: It's *not* that NativeAOT doesn't support P/Invokes; it does.
The problem is that for a P/Invoke to work, we need to know the
name of the native library we're P/Invoking into, and our
NativeAOT sample environment doesn't include any `.so` files
other than the one for the app, i.e. whatever we'd P/Invoke
into doesn't exist.
// FIXME: Since a Dictionary<Type, Func> is used here, the trimmer will not be able to properly analyze `Type t`
668
+
// error IL2111: Method 'lambda expression' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.
0 commit comments