Android NDK C++ JNI(没有找到原生的实现......) [英] Android NDK C++ JNI (no implementation found for native...)

查看:27
本文介绍了Android NDK C++ JNI(没有找到原生的实现......)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 NDK 与 C++ 一起使用,但似乎无法使方法命名约定正确.我的原生方法如下:

I'm trying to use the NDK with C++ and can't seem to get the method naming convention correct. my native method is as follows:

extern "C" {
JNIEXPORT void JNICALL Java_com_test_jnitest_SurfaceRenderer_drawFromJni
(JNIEnv* env, jclass c)
{
   //
}
}

还有一个包含在 extern "C" {} 中的标题.

with a header wrapped in extern "C" {} aslo.

一切都编译得很好,创建了一个 .so 文件并复制到我的项目下的 libs 文件夹,但是当我在 Eclipse 中调试和运行时,我不断收到一条日志猫消息,即没有找到本机的实现......".由于所有 NDK 示例都在 C 中,我是否缺少一些东西?

Everything compiles fine, creates a .so file and copies to the libs folder under my project, but when I debug and run in Eclipse I keep getting a log cat message that of "no implementation found for native...". Is there something i'm missing as all the NDK examples are in C?

谢谢.

推荐答案

有几件事会导致找不到实现".一个是函数原型名称错误,另一个是根本无法加载 .so.您确定在使用方法之前调用了 System.loadLibrary() 吗?

There are a couple of things that can lead to "no implementation found". One is getting the function prototype name wrong, another is failing to load the .so at all. Are you sure that System.loadLibrary() is being called before the method is used?

如果您没有定义 JNI_OnLoad 函数,您可能需要创建一个并让它输出一条日志消息,以验证该库是否已成功拉入.

If you don't have a JNI_OnLoad function defined, you may want to create one and have it spit out a log message just to verify that the lib is getting pulled in successfully.

您已经避开了最常见的问题——忘记使用 extern "C"——所以要么是上述问题,要么是一些轻微的拼写错误.Java 声明是什么样的?

You already dodged the most common problem -- forgetting to use extern "C" -- so it's either the above or some slight misspelling. What does the Java declaration look like?

这篇关于Android NDK C++ JNI(没有找到原生的实现......)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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