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
Asked
Active
Viewed 2.8k times
2 Answers
16
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.

Maxim Makhun
- 2,197
- 1
- 22
- 26

gby
- 14,900
- 40
- 57
-
my 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) – Andrea Giancarli May 23 '11 at 11:49
-
Post 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. – gby May 23 '11 at 13:34
-
I solved it. it was only an error in the makefile with a define. thanks anyway – Andrea Giancarli May 24 '11 at 09:17
-
Don't you also need to put `JNICALL` after **void**? – IgorGanapolsky May 11 '16 at 21:24
15
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.
-
You 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. – Genar Jul 24 '14 at 10:57