如何调用从Android的使用JNA C / C ++ code? [英] How do i call C/C++ code from Android using JNA?

查看:380
本文介绍了如何调用从Android的使用JNA C / C ++ code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这个特定的库集成到我的Andr​​oid项目,以及该库是用C / C ++。我已经奇迹般地得到了 NDK建造给我所需要的的.so 文件。

I'm trying to integrate this specific library to my Android project, and the library is written in C/C++. I've miraculously gotten ndk-build to give me the needed .so file.

不过,看着它,有一个在项目中的样品,他们用一种神秘的的.jar 用的API的绑定 .C / C ++ 文件。

However, looking at it, there's a sample in the project, and they use a mysterious .jar with the API bindings of the .c/c++ files.

我如何为

  • 创建这个特殊的的.jar 文件具有API的基础上,的.so
  • create this special .jar file that has the API, based on the .so?

  • 直接添加一个方法来主 C ++ 文件,然后从Java调用它?
  • directly add a method to the main c++ file and then call it from Java?

我试着重新包装使用JNI的东西,但它肯定似乎并没有工作。我不断收到的UnsatisfiedLinkError

I've tried to re-wrap things using JNI, but it definitely doesn't seem to work. i keep getting UnsatisfiedLinkError.

很多文档的在线使用JNI的教程。我很高兴,只需几个链接教程JNA。

A lot of the documentation online uses jni as the tutorial. i'm happy with just a few links to tutorials on JNA.

推荐答案

JNA提供存根本地库, libjnidispatch.so 适用于各种平台。你可以建立这个库自己,或者提取物项目的的lib /本地/&LT的pre生成的二进制文件之一;平台>的.jar

JNA provides a stub native library, libjnidispatch.so for a variety of platforms. You can build this library yourself, or extract one of the pre-built binaries from the project's lib/native/<platform>.jar packages.

您在你的Andr​​oid项目包括 libjnidispatch.so 的方式将其他任何JNI库。这是必需的;你不能靠JNA动态自动解压并使用其本地库像在其他平台上。该JNA项目包括细节,这样做(以及指令建筑 libjnidispatch.so 自己)。

You include libjnidispatch.so in your Android project the way you would any other JNI library. This is required; you cannot rely on JNA to dynamically unpack and use its native library automatically like on other platforms. The JNA project includes details for doing so (as well as instructions for building libjnidispatch.so yourself).

您再使用 jna.jar ,就像任何其他Java jar文件,并编写您自己(JAVA)的映射来匹配您试图访问本机库。还有一个 JNA-min.jar 其省略了所有在 jna.jar 通常捆绑在本地平台库。

You then use jna.jar as you would any other Java jar file, and write your own (Java) mappings to match the native library you're trying to access. There's also a jna-min.jar which omits all the native platform libraries that are normally bundled in jna.jar.

这篇关于如何调用从Android的使用JNA C / C ++ code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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