Skip to content

[Mono.Android] use Java.Lang.Object.GetObject<T>() #9860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

jonathanpeppers
Copy link
Member

f800c1a was a step toward making Java.Lang.Object.GetObject<T>() to not call the static Java.Interop.TypeManager.CreateInstance() and go through a JniRuntime.JniValueManager instead.

Unfortunately, there are still a few types that manually call TypeManager.CreateInstance(), these will error when running with NativeAOT such as Mono.Android.NET-Tests:

02-27 14:40:23.089  9462  9487 I NUnit   : AssetContents("asset1.txt","Asset1")
02-27 14:40:23.093  9462  9487 E NUnit   :      [FAIL]
02-27 14:40:23.093  9462  9487 E NUnit   :  : System.DllNotFoundException : DllNotFound_Linux, xa-internal-api,
02-27 14:40:23.093  9462  9487 E NUnit   : dlopen failed: library "xa-internal-api.so" not found
02-27 14:40:23.093  9462  9487 E NUnit   : dlopen failed: library "libxa-internal-api.so" not found
02-27 14:40:23.093  9462  9487 E NUnit   : dlopen failed: library "xa-internal-api" not found
02-27 14:40:23.093  9462  9487 E NUnit   : dlopen failed: library "libxa-internal-api" not found
02-27 14:40:23.093  9462  9487 E NUnit   :    at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x4c
02-27 14:40:23.093  9462  9487 E NUnit   :    at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x134
02-27 14:40:23.093  9462  9487 E NUnit   :    at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x40
02-27 14:40:23.093  9462  9487 E NUnit   :    at Android.Runtime.RuntimeNativeMethods.monodroid_TypeManager_get_java_class_name(IntPtr klass) + 0x2c
02-27 14:40:23.093  9462  9487 E NUnit   :    at Java.Interop.TypeManager.GetClassName(IntPtr) + 0x10
02-27 14:40:23.093  9462  9487 E NUnit   :    at Java.Interop.TypeManager.CreateInstance(IntPtr, JniHandleOwnership, Type) + 0x44
02-27 14:40:23.093  9462  9487 E NUnit   :    at Android.Runtime.InputStreamInvoker.FromJniHandle(IntPtr handle, JniHandleOwnership transfer) + 0x60
02-27 14:40:23.093  9462  9487 E NUnit   :    at Android.Content.Res.AssetManager.Open(String) + 0x88
02-27 14:40:23.093  9462  9487 E NUnit   :    at Android.Content.ResTests.AssetManagerTests.AssetContents(String asset, String expected) + 0x34
02-27 14:40:23.093  9462  9487 E NUnit   :    at libMono.Android.NET-Tests!<BaseAddress>+0x155be18
02-27 14:40:23.093  9462  9487 E NUnit   :    at System.Reflection.DynamicInvokeInfo.InvokeWithFewArguments(IntPtr, Byte&, Byte&, Object[], BinderBundle, Boolean) + 0x84

Update InputStreamInvoker, OutputStreamInvoker, and XmlPullParserReader to use Java.Lang.Object.GetObject<T>() instead.

f800c1a was a step toward making `Java.Lang.Object.GetObject<T>()` to
not call the static `Java.Interop.TypeManager.CreateInstance()` and go
through a `JniRuntime.JniValueManager` instead.

Unfortunately, there are still a few types that manually call
`TypeManager.CreateInstance()`, these will error when running with
NativeAOT such as `Mono.Android.NET-Tests`:

    02-27 14:40:23.089  9462  9487 I NUnit   : AssetContents("asset1.txt","Asset1")
    02-27 14:40:23.093  9462  9487 E NUnit   :      [FAIL]
    02-27 14:40:23.093  9462  9487 E NUnit   :  : System.DllNotFoundException : DllNotFound_Linux, xa-internal-api,
    02-27 14:40:23.093  9462  9487 E NUnit   : dlopen failed: library "xa-internal-api.so" not found
    02-27 14:40:23.093  9462  9487 E NUnit   : dlopen failed: library "libxa-internal-api.so" not found
    02-27 14:40:23.093  9462  9487 E NUnit   : dlopen failed: library "xa-internal-api" not found
    02-27 14:40:23.093  9462  9487 E NUnit   : dlopen failed: library "libxa-internal-api" not found
    02-27 14:40:23.093  9462  9487 E NUnit   :    at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x4c
    02-27 14:40:23.093  9462  9487 E NUnit   :    at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x134
    02-27 14:40:23.093  9462  9487 E NUnit   :    at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x40
    02-27 14:40:23.093  9462  9487 E NUnit   :    at Android.Runtime.RuntimeNativeMethods.monodroid_TypeManager_get_java_class_name(IntPtr klass) + 0x2c
    02-27 14:40:23.093  9462  9487 E NUnit   :    at Java.Interop.TypeManager.GetClassName(IntPtr) + 0x10
    02-27 14:40:23.093  9462  9487 E NUnit   :    at Java.Interop.TypeManager.CreateInstance(IntPtr, JniHandleOwnership, Type) + 0x44
    02-27 14:40:23.093  9462  9487 E NUnit   :    at Android.Runtime.InputStreamInvoker.FromJniHandle(IntPtr handle, JniHandleOwnership transfer) + 0x60
    02-27 14:40:23.093  9462  9487 E NUnit   :    at Android.Content.Res.AssetManager.Open(String) + 0x88
    02-27 14:40:23.093  9462  9487 E NUnit   :    at Android.Content.ResTests.AssetManagerTests.AssetContents(String asset, String expected) + 0x34
    02-27 14:40:23.093  9462  9487 E NUnit   :    at libMono.Android.NET-Tests!<BaseAddress>+0x155be18
    02-27 14:40:23.093  9462  9487 E NUnit   :    at System.Reflection.DynamicInvokeInfo.InvokeWithFewArguments(IntPtr, Byte&, Byte&, Object[], BinderBundle, Boolean) + 0x84

Update `InputStreamInvoker`, `OutputStreamInvoker`, and
`XmlPullParserReader` to use `Java.Lang.Object.GetObject<T>()` instead.
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/MoreGetObject branch from 5b09113 to 4109448 Compare February 27, 2025 22:25
@jonathanpeppers jonathanpeppers marked this pull request as ready for review February 28, 2025 14:34
@jonpryor jonpryor merged commit dc4f29d into main Feb 28, 2025
58 checks passed
@jonpryor jonpryor deleted the dev/peppers/MoreGetObject branch February 28, 2025 20:03
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants