未找到本机的实现 [英] No implementation found for native

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

问题描述

我用 android-ndk 编译了我的 c 源代码,然后我将 .so 文件放在了我的 android 项目的 libs 文件夹中,但是当我调用本机函数时,我有一个没有找到本机的实现"错误.如果我尝试从 adb shell 调用此函数,一切正常,所以我不明白为什么会出现该错误.请帮忙,安德烈亚

I compiled my c sources with android-ndk then I put the .so file in the libs folder of my android project but when I call the native function i have a "No implementation found for native" error. If I try to call this function from adb shell everything works fine so I don't understand why that error. Please help, Andrea

推荐答案

JNI 有一个确切的命名方案,不是很明显.也许你的函数实现不符合它?

There is an exact naming scheme involved with JNI which is not very obvious. Perhaps your function implementation is not conforming to it?

例如,如果您希望能够从您的 JAVA 代码中调用一个名为 startServer 的本机函数,假设您的包名为 com.example.something 并且您的类名为 MyClass,那么您的 JAVA 中应该有一个成员函数像这样的类:

For example, if you want to be able to call a native function called startServer from your JAVA code, assuming your package is called com.example.something and your class is called MyClass, you should have a member function in your JAVA class like so:

private native void startServer();

然后你的 JNI 实现应该如下所示:

And then your JNI implementation should look like this:

JNIEXPORT void Java_com_example_something_MyClass_startServer(JNIEnv *env, jobject obj) {  

// Do something here...

}

否则会出现联动错误.

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

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