Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNI_OnLoad not found

I started android application development and followed this tutorial:

http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/ but the application didn't work. I debug it and the log cat show this message: JNI_Onload not found..how can I solve this problem?

Thanks

like image 210
NMMA Avatar asked Dec 12 '22 16:12

NMMA


1 Answers

The main purpose of the JNI_OnLoad function is to register all of your native methods.

This is the recommended, but not the only, approach. Thus providing a JNI_OnLoad function is optional. Because it is used to register all native methods, it can discover a signature mismatch between a java native method declaration and its C/C++ counterpart before the method is actually used.

You could instead just load a native library from a static class initializer like that:

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

That way, you won't have to provide a JNI_OnLoad function and all native methods in 'mylib' would be discovered automatically. The only downside is that you won't know if some of your native method signatures is wrong, until you actually call it. In that case you would get an 'unsatisfiedlinkerror' telling you that no implementation was found for the native method you were trying to call.

If you go for this option (Option 2 - automatic discovery), the debug-level message will be just a warning telling you that you have 'forgotten' to provide a JNI_OnLoad function, so you can just ignore it.

For more information just look at the JNI Tips:
http://developer.android.com/guide/practices/jni.html

like image 135
Ivo Avatar answered Dec 15 '22 09:12

Ivo