JNI_OnLoad not found

左心房为你撑大大i 提交于 2019-12-07 11:41:53

问题


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


回答1:


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




回答2:


JNI_OnLoad is a debug-level message that just lets you know that the function wasn't found.

It's there because people occasionally write JNI_OnLoad without the 'extern "C"' declaration and then aren't sure why things don't work.

The problem you're facing is probably unrelated to the message. Look at the nearby logcat output for clues. dlopen() failures and Java exceptions are likely relevant.

You should paste some of that into a question, and perhaps describe the failure in more detail ("didn't work" is a little vague).



来源:https://stackoverflow.com/questions/4921222/jni-onload-not-found

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