No implementation found for native [closed]

*爱你&永不变心* 提交于 2019-12-29 08:42:55

问题


I compiled my c sources with android-ndk then I put the .so file in the libs folder of my android project but when I call the native function i have a "No implementation found for native" error. If I try to call this function from adb shell everything works fine so I don't understand why that error. Please help, Andrea


回答1:


There is an exact naming scheme involved with JNI which is not very obvious. Perhaps your function implementation is not conforming to it?

For example, if you want to be able to call a native function called startServer from your JAVA code, assuming your package is called com.example.something and your class is called MyClass, you should have a member function in your JAVA class like so:

private native void startServer();

And then your JNI implementation should look like this:

JNIEXPORT void Java_com_example_something_MyClass_startServer(JNIEnv *env, jobject obj) {  

// Do something here...

}

Otherwise, there is a linkage error.




回答2:


Another reason you can get this, is if your not calling your library at the time you are making a JNI function call:

static {
    System.loadLibrary("myJNIFILE");
}

should be called somewhere before the actual reference to a JNI function.



来源:https://stackoverflow.com/questions/6096355/no-implementation-found-for-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!