链接第三方库(libs.a)与NDK第三方、链接、NDK、libs

2023-09-03 23:29:18 作者:28.白日依山尽

我要建一个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?

这是我的Andr​​oid.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)

请注意..你应该使用它之前包括模块的Andr​​oid.mk文件。我这样做,与呼叫所有子目录,生成文件。

Note.. you should include the Android.mk file of the module before using it. I do that with the call all-subdir-makefiles.