After updating from r6 to r7, the Android NDK could not find JNI_GetCreatedJavaVMs
I have updated my NDK version from r6 to r7. After that, I got this error while compiling one of my native files :
error: ‘JNI_GetCreatedJavaVMs’ was not declared in this scope
I’m building my project for API level 8 (Android 2.2). I checked
(MY_NDK_PATH_R6)/android-8/arch-arm/usr/include/jni.h
Where GetCreatedJavaVMs
are declared, the file jni.h
is actually
a symbolic link to
(MY_NDK_PATH_R6)/platforms/android-3/arch-arm/usr/include/jni.h
Then I checked
(MY_NDK_PATH_R7)/platforms/android-8/arch-arm/usr/include/jni.h
It’s actually a file, not a symbolic link.
I’m building my project using Eclipse and the only thing I specify in my preferences is the path to ndk-build
.
EDIT: Okay, it’s clear why I can’t find GetCreatedJavaVMs:
/*
* VM initialization functions.
*
* Note these are the only symbols exported for JNI by the VM.
*/
#if 0 /* In practice, these are not exported by the NDK so don't declare them */
jint JNI_GetDefaultJavaVMInitArgs(void*);
jint JNI_CreateJavaVM(JavaVM**, JNIEnv**, void*);
jint JNI_GetCreatedJavaVMs(JavaVM**, jsize, jsize*);
#endif
But how do I get the VM in this case?
Solution
I found a solution.
You only need to implement the JNI_OnLoad (JavaVM* vm, void* reserved) function. The JVM is a parameter.
This might be a better way to get the JVM.