-
Notifications
You must be signed in to change notification settings - Fork 564
Description
Android framework version
net10.0-android (Preview)
Affected platform version
NET 10 RC2
Description
Hi team — thanks a lot for adding initial NativeAOT support for Android! I tried it with my framework and hit two problems.
1) Crash on startup (Reflection.Emit)
The app crashes immediately with:
System.PlatformNotSupportedException: PlatformNotSupported_ReflectionEmit
at System.Reflection.Emit.ReflectionEmitThrower.ThrowPlatformNotSupportedException() + 0x34
at Android.Runtime.JNINativeWrapper.CreateDelegate(Delegate dlg) + 0x308
at MugenMvvm.Android.Native.Interfaces.INativeLifecycleDispatcherInvoker.GetOnLifecycleChanged_Ljava_lang_Object_ILjava_lang_Object_Handler() + 0x60
at Microsoft.Android.Runtime.ManagedTypeManager.RegisterNativeMembers(JniType, Type, ReadOnlySpan`1) + 0x1c0
at Java.Interop.ManagedPeer.RegisterNativeMembers(IntPtr jnienv, IntPtr klass, IntPtr n_nativeClass, IntPtr n_methods) + 0x19c
--- End of stack trace from previous location ---
at Java.Interop.JniEnvironment.Object.AllocObject(JniObjectReference) + 0x18c
at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String, Type, JniArgumentValue*) + 0x2c
at Java.Lang.Object..ctor() + 0x108
at MugenMvvm.Android.AndroidMugenExtensions.AddAndroidCore(MugenApplicationConfiguration, IBindVie
Is Android.Runtime.JNINativeWrapper.CreateDelegate expected to use Reflection.Emit under Android NativeAOT?
2) IL scanner VTable error (linker)
When building for Android AOT I also get:
EXEC : error VTable of type 'Impl`3<MugenMvvm.Views.Interfaces.IViewManager,
MugenMvvm.Api.Interfaces.IApiProviderComponent`1<MugenMvvm.Views.Interfaces.IViewManager>,
MugenMvvm.Bindings.Api.BindingBuilderRequest`1<MugenMvvm.Common.InlineObjectTuple>>'
not computed by the IL scanner. You can work around by running the compilation with scanner disabled.
This generic combination isn’t actually used at runtime. As a workaround I added an explicit reference so the type is kept:
public static class LinkerInclude
{
public static void Include()
{
// Workaround for AOT linking / IL scanner
_ = ComponentDescriptor.Impl<
IViewManager,
IApiProviderComponent<IViewManager>,
BindingBuilderRequest<InlineObjectTuple>
>.EmptyInstance;
}
}Repro repository
Minimal repro (Android + iOS projects): https://github.com/vyacheslav-volkov/NativeAot.Test
Notes:
- The iOS app works fine under NativeAOT with the same framework code.
- The Android app demonstrates the crash.
How I build (Android)
I used the following command to reproduce:
dotnet publish -f net10.0-android -c Release /t:Run -p:AndroidNdkDirectory="pathToRoot/Developer/Xamarin/android-sdk-macosx/ndk/27.2.12479018"(Explicit NDK is r27.2.12479018.)
Thanks again for the NativeAOT work — happy to test any fixes or try suggested changes to the sample.
Steps to Reproduce
Build and run the android app from the link https://github.com/vyacheslav-volkov/NativeAot.Test
Did you find any workaround?
No response