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.
我正在尝试将这个特定的库集成到我的Android项目中,该库是用C / C ++编写的。我奇迹般地得到了ndk-build来给我所需的.so文件。
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与.c / c ++文件的API绑定。
How do i either
我怎么样
- create this special
.jar
file that has the API, based on the.so
?
根据.so创建这个具有API的特殊.jar文件?
OR
- directly add a method to the main
c++
file and then call it from Java?
直接将方法添加到主c ++文件,然后从Java调用它?
I've tried to re-wrap things using JNI, but it definitely doesn't seem to work. i keep getting UnsatisfiedLinkError
.
我试图用JNI重新包装东西,但它肯定似乎不起作用。我一直得到UnsatisfiedLinkError。
A lot of the documentation online uses jni as the tutorial. i'm happy with just a few links to tutorials on JNA.
很多在线文档使用jni作为教程。我很高兴只有一些指向JNA教程的链接。
2 个解决方案
#1
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.
JNA为各种平台提供了一个存根本机库libjnidispatch.so。您可以自己构建此库,也可以从项目的lib / native /
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).
您可以像在任何其他JNI库中一样在Android项目中包含libjnidispatch.so。这是必需的;您不能像其他平台那样依赖JNA动态解压缩和使用其本机库。 JNA项目包括这样做的详细信息(以及自己构建libjnidispatch.so的说明)。
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
.
然后像使用任何其他Java jar文件一样使用jna.jar,并编写自己的(Java)映射以匹配您尝试访问的本机库。还有一个jna-min.jar,它省略了通常捆绑在jna.jar中的所有本机平台库。
#2
Do go to project properties and build paths and remove JNA 4.0 and related classes. This will work!
去项目属性和构建路径并删除JNA 4.0和相关的类。这会奏效!
#1
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.
JNA为各种平台提供了一个存根本机库libjnidispatch.so。您可以自己构建此库,也可以从项目的lib / native /
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).
您可以像在任何其他JNI库中一样在Android项目中包含libjnidispatch.so。这是必需的;您不能像其他平台那样依赖JNA动态解压缩和使用其本机库。 JNA项目包括这样做的详细信息(以及自己构建libjnidispatch.so的说明)。
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
.
然后像使用任何其他Java jar文件一样使用jna.jar,并编写自己的(Java)映射以匹配您尝试访问的本机库。还有一个jna-min.jar,它省略了通常捆绑在jna.jar中的所有本机平台库。
#2
Do go to project properties and build paths and remove JNA 4.0 and related classes. This will work!
去项目属性和构建路径并删除JNA 4.0和相关的类。这会奏效!