-
Notifications
You must be signed in to change notification settings - Fork 563
Labels
Area: App RuntimeIssues in `libmonodroid.so`.Issues in `libmonodroid.so`.bugComponent does not function as intended.Component does not function as intended.need-attentionA xamarin-android contributor needs to reviewA xamarin-android contributor needs to review
Description
Android application type
Classic Xamarin.Android (MonoAndroid12.0, etc.)
Affected platform version
VS 2022 17.4, Xamarin.Android 13.1.0.1
Description
I have a shared library (.so) written in C. The library exports JNI_OnLoad and JNI_OnUnload, confirmed with readelf:
478: 00000000002ff2f0 132 FUNC GLOBAL DEFAULT 13 JNI_OnLoad
3111: 00000000002ff380 297 FUNC GLOBAL DEFAULT 13 JNI_OnUnload
I reference the .so properly in my Xamarin.Android application using AndroidNativeLibrary.
However, at runtime JNI_OnLoad is never invoked.
Steps to Reproduce
See above
Did you find any workaround?
I can invoke JNI_OnLoad manually by first using reflection to get the java_vm pointer:
[DllImport("MyLibrary", CallingConvention = CallingConvention.Cdecl)]
private static extern int JNI_OnLoad(IntPtr vm, IntPtr reserved);
static MyClass()
{
var field = typeof(Android.Runtime.JNIEnv).GetField("java_vm", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
JNI_OnLoad((IntPtr)field.GetValue(null), IntPtr.Zero);
}
But this feels like an ugly workaround.
Relevant log output
N/Agkarabin
Metadata
Metadata
Assignees
Labels
Area: App RuntimeIssues in `libmonodroid.so`.Issues in `libmonodroid.so`.bugComponent does not function as intended.Component does not function as intended.need-attentionA xamarin-android contributor needs to reviewA xamarin-android contributor needs to review