Undefined reference on JNI_GetCreatedJavaVMs in ndk r21b

90 views
Skip to first unread message

Dirar Abu-Saymeh

unread,
May 18, 2020, 10:51:59 AM5/18/20
to android-ndk
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?


Alex Cohn

unread,
Jun 7, 2020, 6:21:40 AM6/7/20
to android-ndk

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
Reply all
Reply to author
Forward
0 new messages