链接第三方库(libs.a)与NDK [英] Linking thirdparty libs (libs.a) with NDK
问题描述
我要建一个Android APK谁使用第三方的一些本地库,这些库是静态对象code库(.a文件),我需要写一个JNI包装在Java中访问这些功能
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。
Those libs are already compiled with a cross-compiler and are natively to Android.
我如何编译我的JNI源链接到功能的。一个库文件?
How do I compile my JNI sources linking to the functions in the .a libs files?
这是我的Android.mk
This is my 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)
当我编译,我只得到了native.c文件编译的。
When I compile, I get only the native.c file compiled.
推荐答案
要做到这一点。
我要声明这些库的模块。像下面的。
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)
通过在同一个文件夹中,因为这Android.mk文件libcurl.a文件和/包括fodler的头。
With a libcurl.a file in the same folder as this Android.mk file, and a /include fodler with the headers.
现在在主模块中只需要声明的lib和Android NDK将完成剩余的工作。
Now in the main module just declare the lib and the Android NDK will take care of the rest.
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)
请注意..你应该使用它之前包括模块的Android.mk文件。我这样做,与呼叫所有子目录,生成文件。
Note.. you should include the Android.mk file of the module before using it. I do that with the call all-subdir-makefiles.
这篇关于链接第三方库(libs.a)与NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!