Reputation: 383
I've got a package called com.example.remote in that package I have a Remote.java file with
public native static void send_feedback(String feedback);
static {
System.loadLibrary("com_example_remote_Remote");
}
then in my com_example_remote_Remote.c file I got this method:
JNIEXPORT void JNICALL Java_com_example_remote_Remote_send_feedback(JNIEnv *env, jclass clazz, jstring feedback)
Everything compiles. But when I do a call to the java function the program stops working and gives me:
12-19 12:21:31.183: E/AndroidRuntime(3196): FATAL EXCEPTION: main
12-19 12:21:31.183: E/AndroidRuntime(3196): java.lang.UnsatisfiedLinkError: Native method not found: com.example.remote.Remote.send_feedback:(Ljava/lang/String;)V
12-19 12:21:31.183: E/AndroidRuntime(3196): at com.example.remote.Remote.send_feedback(Native Method)
I think my syntax is conform the rules of JNI. I deleted the obj map once I thought maybe it would solve the problem. I rebuild the project and still gives me that error.
EDIT:
changed the name to sendFeedback and now I get this error:
12-19 12:49:26.335: A/libc(3280): Fatal signal 11 (SIGSEGV) at 0x00000cd0 (code=0), thread 3280 (.example.remote)
Upvotes: 2
Views: 1354
Reputation: 383
I've changed the name to sendFeedback so it's without the underscore. Also there was an error in the method what doesn't matter for this answer.
Upvotes: 0
Reputation: 4522
Add extern "C"
in native method definition. i.e.
extern "C" JNIEXPORT void JNICALL Java_com_example_remote_Remote_send_feedback(JNIEnv *env, jclass clazz, jstring feedback){.......}
Or
If possible change MethodName in declaration and definition (in java file and .c file) because _
may be problem in method name. i.e.
public native static void sendFeedback(String feedback);
extern "C" JNIEXPORT void JNICALL Java_com_example_remote_Remote_sendFeedback(JNIEnv *env, jclass clazz, jstring feedback)
{
....
}
you may find a sample here
Upvotes: 1