I am able to follow a jni tutorial just fine. But when I change the method name, I run into trouble. Is there a naming convention I need to follow? The tutorial used HelloJNI as the module name, and library name. I used "useaaacom".
解决方案
Dynamic linkers resolve entries based on their names. A native method name is concatenated from the following components:
the prefix Java_
a mangled fully-qualified class name
an underscore (_) separator
a mangled method name
for overloaded native methods, two underscores (__) followed by the mangled argument signature
So if you have the following:
package com.foo.bar;
class Baz {
public native void Grill(int i);
}
Then the corresponding C function should be:
JNIEXPORT void JNICALL Java_com_foo_bar_Baz_Grill(JNIEnv *env, jobject thiz, jint i);
If you have an underscore in the Java method name:
public native void A_Grill(int i);
Then the C function would be:
JNIEXPORT void JNICALL Java_com_foo_bar_Baz_A_1Grill(JNIEnv *env, jobject thiz, jint i);
The _1 escape sequence matches the _ in A_Grill.