JNI_OnLoad not found

I started developing Android applications and followed this guide:

http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/ but the application does not work. I am debugging it, and the log cat shows this message: JNI_Onload was not found .. how can I solve this problem?

thanks

+4
source share
2 answers

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

This is a recommended but not the only approach. Therefore, providing the JNI_OnLoad function is optional . Since it is used to register all native methods, it can detect a signature mismatch between the declaration of the native Java method and its C / C ++ mapping before this method is actually used.

Instead, you can simply load your own library from a static class initializer as follows:

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

This way you will not need to provide the JNI_OnLoad function, and all native methods in mylib will be detected automatically. The only drawback is that you won’t know if some of your signatures of the native method are spelled incorrectly until you actually name it. In this case, you will get an "unsatisfiedlinkerror" telling you that no implementation was found for the native method that you tried to call.

If you use this option (option 2 - automatic detection), a message about the debugging level will be just a warning that you “forgot” to provide the JNI_OnLoad function, so you can simply ignore it .

For more information, just check out the JNI tips:
http://developer.android.com/guide/practices/jni.html

+9
source

JNI_OnLoad is a debugging level message that simply lets you know that a function was not found.

This is there because people sometimes write JNI_OnLoad without declaring "extern" C "', and then are not sure why something is not working.

The problem you are facing is probably not related to the message. Look at nearby logcat output for tips. dlopen () and Java exceptions are probably relevant.

You should insert part of this question into the question and perhaps describe the failure in more detail (“not working” is a bit vague).

+4
source

Source: https://habr.com/ru/post/1338712/


All Articles