我在那个包中有一个名为 com.example.remote 的包 我有一个带有
的 Remote.java 文件public native static void send_feedback(String feedback);
static {
System.loadLibrary("com_example_remote_Remote");
}
然后在我的 com_example_remote_Remote.c 文件中我得到了这个方法:
JNIEXPORT void JNICALL Java_com_example_remote_Remote_send_feedback(JNIEnv *env, jclass clazz, jstring feedback)
一切都编译。但是当我调用 java 函数时程序停止工作并给我:
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)
我认为我的语法符合 JNI 的规则。一旦我认为它可能会解决问题,我就删除了 obj 贴图。我重建了项目,但仍然出现该错误。
编辑:
将名称更改为 sendFeedback,现在出现此错误:
12-19 12:49:26.335: A/libc(3280): Fatal signal 11 (SIGSEGV) at 0x00000cd0 (code=0), thread 3280 (.example.remote)
最佳答案
在本地方法定义中添加extern "C"
。即
extern "C" JNIEXPORT void JNICALL Java_com_example_remote_Remote_send_feedback(JNIEnv *env, jclass clazz, jstring feedback){.......}
或者
如果可能,请更改声明和定义中的 MethodName(在 java 文件和 .c 文件中),因为 _
可能是方法名称中的问题。即
public native static void sendFeedback(String feedback);
extern "C" JNIEXPORT void JNICALL Java_com_example_remote_Remote_sendFeedback(JNIEnv *env, jclass clazz, jstring feedback)
{
....
}
您可能会找到一个样本 here
关于java - 未找到 JNI native 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20680693/