我正在构建一个使用第三方本地库的 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 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
上传进度侦听器未触发(Google 驱动器 API)Upload progress listener not fired (Google drive API)(上传进度侦听器未触发(Google 驱动器 API))
使用 Google Drive SDK 将文件保存在特定文件夹中Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 将文件保存在特定文件夹中)
Google Drive Android API - 无效的 DriveId 和 Null ResourcGoogle Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 无效的 DriveId 和 Null ResourceId)
谷歌驱动api服务账户查看上传文件到谷歌驱动使Google drive api services account view uploaded files to google drive using java(谷歌驱动api服务账户查看上传文件到谷歌驱动使用java
Google Drive 服务帐号返回 403 usageLimitsGoogle Drive service account returns 403 usageLimits(Google Drive 服务帐号返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory;Google Drcom.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例