UnsatisfiedLinkError problem
I'm developing an Android application that uses JNI.
The command javah -jni com.company.tests.MainRenderer
gave me this output:
/*
* Class: com_company_tests_MainRenderer
* Method: nativeInit
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_company_tests_MainRenderer_nativeInit
(JNIEnv *, jclass);
/*
* Class: com_company_tests_MainRenderer
* Method: nativeRender
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_company_tests_MainRenderer_nativeRender
(JNIEnv *, jclass);
The command nm -Ca libRotateJNI.so
gave me this output:
00001c25 T Java_com_company_tests_MainRenderer_nativeInit(_JNIEnv*, _jclass*)
00001c29 T Java_com_company_tests_MainRenderer_nativeRe开发者_如何学运维nder(_JNIEnv*, _jclass*)
This is how are defined these functions:
void Java_com_company_tests_MainRenderer_nativeInit( JNIEnv* env, jobject thiz )
{
// ...
}
void Java_com_company_tests_MainRenderer_nativeRender( JNIEnv* env, jobject thiz )
{
// ...
}
And running it with this message:
WARN/dalvikvm(639): No implementation found for native Lcom/company/tests/MainRenderer;.nativeInit ()V
I'm sure library is loaded. Do you know how can I fix this problem?
I suspect you compiled your native methods with a C++ compiler, and didn't give them extern "C"
linkage. The -C
option you're providing to nm
demangles the C++ names, but in reality, the symbols have names different from what the JVM is looking for because the code was compiled with C++ linkage. Enclose your C++ code in an extern "C"
block and this should clear things up.
I don't know what your MainRenderer is and what native library you are hitting but my c file functions always look something like this:
void Java_com_ndkfoo_NDKFooActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {
The method/class I am calling is NDKFooActivity and its invoking a native Function...
精彩评论