未找到本机的实现
我使用 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JNI 有一个确切的命名方案,但不是很明显。也许你的函数实现不符合它?
例如,如果您希望能够从 JAVA 代码中调用名为 startServer 的本机函数,假设您的包名为 com.example.something 并且您的类名为 MyClass,那么您的 JAVA 类中应该有一个成员函数,如下所示:
然后你的 JNI 实现应该是这样的:
否则,就会出现链接错误。
There is an exact naming scheme involved with JNI which is not very obvious. Perhaps your function implementation is not conforming to it?
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:
And then your JNI implementation should look like this:
Otherwise, there is a linkage error.
您可以获得此信息的另一个原因是,如果您在进行 JNI 函数调用时没有调用您的库:
应该在实际引用 JNI 函数之前在某处调用。
Another reason you can get this, is if your not calling your library at the time you are making a JNI function call:
should be called somewhere before the actual reference to a JNI function.