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

Linking thirdparty libs (libs.a) with NDK(将第三方库 (libs.a) 与 NDK 链接)

本文介绍了将第三方库 (libs.a) 与 NDK 链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用第三方本地库的 Android apk,这些库位于静态对象代码库(.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.

如何编译链接到 .a libs 文件中的函数的 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 文件,以及一个带有标头的/include 文件夹.

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 文件.我通过调用 all-subdir-makefiles 来做到这一点.

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 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将第三方库 (libs.a) 与 NDK 链接