java 将第三方库 (libs.a) 与 NDK 链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4563928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linking thirdparty libs (libs.a) with NDK
提问by Marcos Vasconcelos
I'm building an Android apk who uses some native libraries of a third party, these libs are in Static Object Code Library (.a files) and I need to write a JNI wrapper to access in Java these functions.
我正在构建一个使用第三方本机库的 Android apk,这些库位于静态对象代码库(.a 文件)中,我需要编写一个 JNI 包装器以在 Java 中访问这些函数。
Those libs are already compiled with a cross-compiler and are natively to Android.
这些库已经用交叉编译器编译过,并且是 Android 原生的。
How do I compile my JNI sources linking to the functions in the .a libs files?
如何编译链接到 .a libs 文件中的函数的 JNI 源?
This is my Android.mk
这是我的 Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := ndk1
LOCAL_SRC_FILES := native.c
include $(BUILD_SHARED_LIBRARY)
When I compile, I get only the native.c file compiled.
当我编译时,我只编译了 native.c 文件。
回答by Marcos Vasconcelos
To do that.
要做到这一点。
I have to declare these libs as modules. Like the following.
我必须将这些库声明为模块。像下面这样。
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := curl
LOCAL_SRC_FILES := libcurl.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
With a libcurl.a file in the same folder as this Android.mk file, and a /include fodler with the headers.
与此 Android.mk 文件位于同一文件夹中的 libcurl.a 文件,以及带有标题的 /include fodler。
Now in the main module just declare the lib and the Android NDK will take care of the rest.
现在在主模块中只需声明 lib,Android NDK 将负责其余的工作。
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog -ldl
LOCAL_MODULE := rmsdk
LOCAL_SRC_FILES := curlnetprovider.cpp native.c
LOCAL_STATIC_LIBRARIES := curl
include $(BUILD_SHARED_LIBRARY)
Note.. you should include the Android.mk file of the module before using it. I do that with the call all-subdir-makefiles.
注意.. 在使用该模块之前,您应该包含该模块的 Android.mk 文件。我通过调用 all-subdir-makefiles 来做到这一点。
回答by thbusch
Your libs have to be compiled for your specific target (Arm), to do that I think you have to use the toolchain as described in docs/STANDALONE-TOOLCHAIN.html (in your ndk-r5 folder).
您的库必须针对您的特定目标(Arm)进行编译,为此我认为您必须使用 docs/STANDALONE-TOOLCHAIN.html(在您的 ndk-r5 文件夹中)中所述的工具链。