In my C++ side I have :
extern "C" {
JNIEXPORT void JNICALL test(JNIEnv*, jobject){}
}
My Acivity has a declared method :
public native void test();
However when I call test I get the error native method not found. What's the problem ?
In my C++ side I have :
extern "C" {
JNIEXPORT void JNICALL test(JNIEnv*, jobject){}
}
My Acivity has a declared method :
public native void test();
However when I call test I get the error native method not found. What's the problem ?
JNI is not looking for a function test
. The name it looks for is of the form Java_packagename_classname_functionname
. For example, if your class is
package your.package;
public class Activity {
static {
System.loadLibrary("your_library");
}
public native void test();
}
Then your library has to contain a function
extern "C" JNIEXPORT void JNICALL Java_your_package_Activity_test(JNIEnv *, jobject) { }
...assuming that test
is not overloaded. If test
is overloaded, use the javah
program to generate a header for you because you don't want to do that manually.
javah your.package.Activity
will generate a file your_package_Activity.h
that contains the function signatures you need. Note that this requires the Activity
class to be compiled, i.e., there has to be a file your/package/Activity.class
in the class path.