No implementation found for native
Solution 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.
Solution 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.
Andrea Giancarli
Updated on September 24, 2020Comments
-
Andrea Giancarli over 3 years
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
-
Andrea Giancarli almost 13 yearsmy package is: package upmt.os; and the function: public static native String upmtconf(String[] param); in the Module class. In the c code the implementation is JNIEXPORT jstring JNICALL Java_upmt_os_Module_upmtconf(JNIEnv * env, jobject obj, jobjectArray param)
-
Kho Dam almost 13 yearsPost the logcat output for calling your function - it has has the exact name the linker is looking for. If you have some sort of typo it's a good way to catch it.
-
Andrea Giancarli almost 13 yearsI solved it. it was only an error in the makefile with a define. thanks anyway
-
Genar almost 10 yearsYou are totally right! I had an app which works properly but I added additional initial screens (views) and the app crashes (I had a JNI warning complaining that a "native" method could not be found). Finally I moved the call: static { System.loadLibrary("mylibrary"); } in the Activity responsible for launching the app.
-
IgorGanapolsky almost 8 yearsDon't you also need to put
JNICALL
after void?