多(我和第三方)购买Android NDK本地库 [英] multiple (my and 3rd-party) native libraries in Android NDK

查看:166
本文介绍了多(我和第三方)购买Android NDK本地库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用两个本地库:一个是我自己的,另一种是第三方。只要我用他们在不同的项目,一切正常。但是现在我发现了异常Ljava /朗/的UnsatisfiedLinkError

I have to use two native libraries: one is my own and the other one is 3rd-party. As long as I used them in separate projects, everything was ok. But now I'm getting the Exception Ljava/lang/UnsatisfiedLinkError.

我使用Eclipse。

I'm using Eclipse.

我发现,如果我把现有的库库/ armeabi,Eclipse将开始本土code的编译和失败。如果我在命令行重建JNI的一部分,编译成功,但第三方库中消失。真的傻了。

I found out that if I place the existing library in libs/armeabi, Eclipse begins compilation of the native code and it fails. If I rebuild the JNI part from the command line, compilation succeeds but the 3rd party library disappears. Really stupid.

那我怎么告诉Eclipse与必须建立一个函数库一起使用现有的.so库?该库是独立的。

So how do I tell Eclipse to use an existing .so library along with a library that must be built? The libraries are independent.

推荐答案

NDK的允许与prebuilt用户库进行链接,使用preBUILT_SHARED_LIBRARY变量。

The NDK allows for linking with prebuilt user libraries, using the PREBUILT_SHARED_LIBRARY variable.

假设你需要链接库是librandom.so,创建一个文件夹中的 JNI 子文件夹项目文件夹:

Assuming that the library you need to link is librandom.so, create a libs folder in jni subfolder of the project folder:

mkdir -p jni/libs
cp librandom.so jni/libs

然后,只需创建一个 JNI /库/ Android.mk 文件:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := random
LOCAL_SRC_FILES := librandom.so
include $(PREBUILT_SHARED_LIBRARY)

您可以为每个prebuilt库中的部分,全部放在 JNI /库

You can create a section for each prebuilt library, all placed in jni/libs.

接下来,你只需要包含上面的文件到您的JNI / Android.mk得到的东西的工作。在NDK文档,建议这在Android.mk年底完成,而不是中间的:

Next, you just need to include the above file into your jni/Android.mk to get things to work. In the NDK docs, it is recommended that this be done at the end of the Android.mk, rather than the middle:

include $(LOCAL_PATH)/libs/Android.mk

不过,你需要需要此库模块之前做到这一点。

However, you'll need to do this before the module that requires this library.

有关链接,你需要添加以下内容链接到prebuilt库模块部分。

For linking, you'll need to add the following into the module section that links to the prebuilt library.

LOCAL_SHARED_LIBRARIES := random

然后,当你做NDK的构建,将这个库复制到库/ armeabi / 之前构建模块,你是好去。

Then when you do ndk-build, it will copy this library into libs/armeabi/ before building the module, and you're good to go.

请注意:这不会解决所需的标题问题。你仍然需要添加标题为库的位置到需要它的模块中的变量 LOCAL_C_INCLUDES

Note: This does not solve problems with required headers. You'll still need to add the location of the headers for the library into the variable LOCAL_C_INCLUDES in the module that requires it.

这篇关于多(我和第三方)购买Android NDK本地库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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