JNI_OnLoad未找到 [英] JNI_OnLoad not found

查看:233
本文介绍了JNI_OnLoad未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始android应用开发和遵循本教程:

I started android application development and followed this tutorial:

http://mindtherobot.com/blog / 452 / Android的初学者,NDK-设置一步一步/
 但应用程序没有工作。
我调试它,并在日志猫显示此消息:
JNI_Onload不found..how我能解决这个问题?

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?

感谢

推荐答案

在JNI_OnLoad函数的主要目的是为了登记所有的本地方法。

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

这是建议,但不是唯一的,途径。因此,提供JNI_OnLoad功能是可选的即可。因为它是用来注册所有的本地方法,它可以发现一个java本地方法的声明和C / C ++对应的签名不匹配实际使用的方法之前。

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");
}

这样的话,你就不必提供JNI_OnLoad功能和MYLIB会自动发现所有的本地方法。唯一的缺点是,你不会知道,如果你的一些原始方法签名是错误的,直到你真正调用它。在这种情况下,你会得到一个的UnsatisfiedLinkError告诉你,没有实现发现你试图调用本地方法。

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.

如果你去为这个选项(选项2 - 自动发现),调试级消息将只是告诉你,你已经被遗忘提供了JNI_OnLoad功能的警告,因此你可以忽略它

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.

有关详细信息,只是看看JNI温馨提示:结果
<一href=\"http://developer.android.com/guide/practices/jni.html\">http://developer.android.com/guide/practices/jni.html

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

这篇关于JNI_OnLoad未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆