From 823b29b05e89f5147d904162aa4b8f3818bbaae5 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 21 Feb 2025 10:38:52 -0600 Subject: [PATCH] [Mono.Android] use `GetJniTypeNameFromInstance()` A .NET MAUI + NativeAOT project fails with: 02-21 10:24:09.913 21462 21462 E AndroidRuntime: net.dot.jni.internal.JavaProxyThrowable: System.DllNotFoundException: DllNotFound_Linux, xa-internal-api, 02-21 10:24:09.913 21462 21462 E AndroidRuntime: dlopen failed: library "xa-internal-api.so" not found 02-21 10:24:09.913 21462 21462 E AndroidRuntime: dlopen failed: library "libxa-internal-api.so" not found 02-21 10:24:09.913 21462 21462 E AndroidRuntime: dlopen failed: library "xa-internal-api" not found 02-21 10:24:09.913 21462 21462 E AndroidRuntime: dlopen failed: library "libxa-internal-api" not found 02-21 10:24:09.913 21462 21462 E AndroidRuntime: 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x4c 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0xe4 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x40 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Android.Runtime.RuntimeNativeMethods.monodroid_TypeManager_get_java_class_name(IntPtr) + 0x2c 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Java.Interop.TypeManager.GetClassName(IntPtr) + 0x10 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Android.Runtime.JNIEnv.GetClassNameFromInstance(IntPtr) + 0x1c 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Android.Runtime.JNIEnv.GetConverter[TValue](Dictionary`2, Type, IntPtr) + 0x6c 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Android.Runtime.JNIEnv.CopyArray[T](IntPtr, T[]) + 0x90 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Android.Graphics.Drawables.LayerDrawable..ctor(Drawable[] layers) + 0x1a4 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Platform.MauiRippleDrawableExtensions.UpdateMauiRippleDrawableBackground(View, Paint, IButtonStroke, Func`1, Func`1, Action) + 0x2ac 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler, IElement) + 0x64 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler) + 0x124 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement, IMauiContext) + 0x160 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement, IMauiContext) + 0x28 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView) + 0xd4 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler) + 0x124 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement, IMauiContext) + 0x160 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement, IMauiContext) + 0x28 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Handlers.ScrollViewHandler.UpdateInsetView(IScrollView, IScrollViewHandler, ICrossPlatformLayout) + 0x34 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler, IElement) + 0x64 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler) + 0x124 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement, IMauiContext) + 0x160 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement, IMauiContext) + 0x28 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler) + 0xb4 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler, IElement) + 0x64 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView) + 0x18 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler) + 0x124 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement, IMauiContext) + 0x160 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement, IMauiContext) + 0x28 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at Microsoft.Maui.Controls.Platform.Compatibility.ShellFragmentContainer.OnCreateView(LayoutInflater, ViewGroup, Bundle) + 0x64 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState) + 0x104 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at crc640ec207abc449b2ca.ShellFragmentContainer.n_onCreateView(Native Method) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at crc640ec207abc449b2ca.ShellFragmentContainer.onCreateView(ShellFragmentContainer.java:38) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.fragment.app.Fragment.performCreateView(Fragment.java:3119) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:577) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:286) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2214) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2109) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:2002) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:317) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.viewpager2.adapter.FragmentStateAdapter.placeFragmentInViewHolder(FragmentStateAdapter.java:342) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:273) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:73) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView.dispatchChildAttached(RecyclerView.java:8377) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView$5.addView(RecyclerView.java:954) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.ChildHelper.addView(ChildHelper.java:131) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:9430) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:9388) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:9375) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1676) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1622) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:687) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4645) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4348) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4919) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.viewpager2.widget.ViewPager2.onLayout(ViewPager2.java:535) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:149) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:43) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:2365) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:953) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1891) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1729) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.LinearLayout.onLayout(LinearLayout.java:1638) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1273) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1891) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1880) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.LinearLayout.onLayout(LinearLayout.java:1640) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1891) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1729) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.LinearLayout.onLayout(LinearLayout.java:1638) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at com.android.internal.policy.DecorView.onLayout(DecorView.java:807) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.View.layout(View.java:25159) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6460) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:4562) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3830) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2718) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9937) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1406) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1415) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:1015) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:945) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1389) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:959) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:100) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:232) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.os.Looper.loop(Looper.java:317) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8592) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580) 02-21 10:24:09.913 21462 21462 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878) It looks like we can update `Android.Runtime.JNIEnv.GetClassNameFromInstance()` to not call `Java.Interop.TypeManager.GetClassName()` and instead call `JniEnvironment.Types.GetJniTypeNameFromInstance()`. --- src/Mono.Android/Android.Runtime/JNIEnv.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Mono.Android/Android.Runtime/JNIEnv.cs b/src/Mono.Android/Android.Runtime/JNIEnv.cs index 3f6b49e5d1b..01fb5c03572 100644 --- a/src/Mono.Android/Android.Runtime/JNIEnv.cs +++ b/src/Mono.Android/Android.Runtime/JNIEnv.cs @@ -396,12 +396,7 @@ public static unsafe IntPtr NewObject (IntPtr jclass, IntPtr jmethod, params JVa public static string GetClassNameFromInstance (IntPtr jobject) { - IntPtr jclass = GetObjectClass (jobject); - try { - return Java.Interop.TypeManager.GetClassName (jclass); - } finally { - DeleteLocalRef (jclass); - } + return JniEnvironment.Types.GetJniTypeNameFromInstance (new JniObjectReference (jobject)); } [MethodImplAttribute(MethodImplOptions.InternalCall)]