Undefined reference on JNI_GetCreatedJavaVMs in ndk r21b

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Undefined reference on JNI_GetCreatedJavaVMs in ndk r21b

Dirar Abu-Saymeh
Hi,

I have a C library that utilizes JNI_OnLoad to cache the VM pointer. However, when using the library in Xamarin.Android, the JNI_OnLoad method is not invoked.So I was trying to use the JNI_GetCreatedJavaVMs to get the JavaVM pointer, but it seems that this function was not exported in earlier NDKs. When I look at the latest version of the NDK, the 
sysroot/usr/include/jni.h file has this function exported.

When I try to use it, I still get undefined reference on JNI_GetCreatedJavaVMs. 

Does the latest version of the NDK actually export this method? Is there a specific library that I need to link with?


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/fab53895-b511-4c7f-9a0d-a19758cbdf0b%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Undefined reference on JNI_GetCreatedJavaVMs in ndk r21b

Alex Cohn
On Monday, May 18, 2020 at 5:51:59 PM UTC+3, Dirar Abu-Saymeh wrote:
Hi,

I have a C library that utilizes JNI_OnLoad to cache the VM pointer. However, when using the library in Xamarin.Android, the JNI_OnLoad method is not invoked.So I was trying to use the JNI_GetCreatedJavaVMs to get the JavaVM pointer, but it seems that this function was not exported in earlier NDKs. When I look at the latest version of the NDK, the 
sysroot/usr/include/jni.h file has this function exported.

When I try to use it, I still get undefined reference on JNI_GetCreatedJavaVMs. 

Does the latest version of the NDK actually export this method? Is there a specific library that I need to link with?

The short answer is "NO". This function is not, and never has been, exported on Android.

The longer answer is that Xamarin itself works though JNI and has access to the JavaVM pointer, so you don't need **JNI_OnLoad()** to find it. But if this is a 3-rd party library that you cannot change, you still can cause a valid JNI_OnLoad() call if you issue Runtime.LoadLibrary() either from some Java code (the easiest), or from your Xamarin code. Make sure to o that before you need any services of this library.

BR,
Alex Cohn

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/7bd33dd5-da35-495c-b984-4d825a1024bao%40googlegroups.com.