Skip to content

Commit 8f6945f

Browse files
[Mono.Android] fix JavaConvert.GetTypeMapping() for NativeAOT (#9864)
Context: #9846 Mono.Android-Tests running on NativeAOT can have a failure such as: I NUnit : Indexer E NUnit : [FAIL] E NUnit : : System.DllNotFoundException : DllNotFound_Linux, xa-internal-api, E NUnit : dlopen failed: library "xa-internal-api.so" not found E NUnit : dlopen failed: library "libxa-internal-api.so" not found E NUnit : dlopen failed: library "xa-internal-api" not found E NUnit : dlopen failed: library "libxa-internal-api" not found E NUnit : at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x4c E NUnit : at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x134 E NUnit : at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x40 E NUnit : at Android.Runtime.RuntimeNativeMethods.monodroid_TypeManager_get_java_class_name(IntPtr klass) + 0x2c E NUnit : at Java.Interop.TypeManager.GetClassName(IntPtr) + 0x10 E NUnit : at Java.Interop.JavaConvert.GetTypeMapping(IntPtr) + 0x28 E NUnit : at Java.Interop.JavaConvert.FromJniHandle(IntPtr handle, JniHandleOwnership transfer, Type targetType) + 0x84 E NUnit : at Android.Runtime.JavaList.InternalGet(Int32, Type) + 0x90 E NUnit : at Java.InteropTests.JavaListTest`1.Indexer() + 0xfc E NUnit : at libMono.Android.NET-Tests!<BaseAddress>+0x152f744 E NUnit : at System.Reflection.DynamicInvokeInfo.Invoke(Object, IntPtr, Object[], BinderBundle, Boolean) + 0x10c We can update `JavaConvert.GetTypeMapping()` to use `JniEnvironment.Types.GetJniTypeNameFromClass()` the same way it is [done in dotnet/java-interop][0]. With this change the test passes: I NUnit : Indexer I NUnit : Passed [0]: https://github.com/dotnet/java-interop/blob/719e615910923bbce10e74b05bcc6b9585d4e176/src/Java.Interop/Java.Interop/JniEnvironment.Types.cs#L214-L220
1 parent 8518ee0 commit 8f6945f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Mono.Android/Java.Interop/JavaConvert.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public static T? FromJniHandle<
208208
{
209209
var lref = JniEnvironment.Types.GetObjectClass (new JniObjectReference (handle));
210210
try {
211-
string className = TypeManager.GetClassName (lref.Handle);
211+
string className = JniEnvironment.Types.GetJniTypeNameFromClass (lref);
212212
if (TypeMappings.TryGetValue (className, out var match))
213213
return match;
214214
if (JniEnvironment.Types.IsAssignableFrom (lref, new JniObjectReference (JavaDictionary.map_class)))

0 commit comments

Comments
 (0)