android ndk Using Prebuilt Libraries
来源:互联网 发布:怎样提高淘宝信誉度 编辑:程序博客网 时间:2024/05/23 19:19
Using Prebuilt Libraries
On this page
- Declaring a Prebuilt Library
- Referencing the Prebuilt Library from Other Modules
- Debugging Prebuilt Libraries
- Selecting ABIs for Prebuilt Libraries
The NDK supports the use of prebuilt libraries, both static and shared. There are two principal use cases for this functionality:
- Distributing分配 your own libraries to third-party NDK developers without distributing your sources.
- Using a prebuilt version of your own libraries to speed up your build.
This page explains how to use prebuilt libraries.
Declaring a Prebuilt Library声明一个预先构建的库
You must declare each prebuilt library you use as a single independent module. To do so, perform the following steps:
- Give the module a name. This name does not need to be the same as that of the prebuilt library, itself.
- In the module's
Android.mk
file, assign toLOCAL_SRC_FILES
the path to the prebuilt library you are providing. Specify the path relative to the value of yourLOCAL_PATH
variable.Note: You must make sure to select the version of your prebuilt library appropriate to your target ABI. For more information on ensuring library support for ABIs, see Selecting ABIs for Prebuilt Libraries.
- Include
PREBUILT_SHARED_LIBRARY
orPREBUILT_STATIC_LIBRARY
, depending on whether you are using a shared (.so
) or static (.a
) library.
Here is a trivial微小的 example that assumes假定 the prebuilt library libfoo.so
resides存在 in the same directory as theAndroid.mk
file that describes it.
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := foo-prebuiltLOCAL_SRC_FILES := libfoo.soinclude $(PREBUILT_SHARED_LIBRARY)
In this example, the name of the module is the same as that of the prebuilt library.
The build system places a copy of your prebuilt shared library into $PROJECT/obj/local
, and another copy, stripped剥去的 of debug information, into $PROJECT/libs/<abi>
. Here, $PROJECT
is the root directory of your project.
Referencing the Prebuilt Library from Other Modules
To reference a prebuilt library from other modules, specify its name as the value of the LOCAL_STATIC_LIBRARIES
or LOCAL_SHARED_LIBRARIES
variable in the Android.mk
files associated相关的 with those other modules.
For example, the description of a module using libfoo.so
might be as follows:
include $(CLEAR_VARS)LOCAL_MODULE := foo-userLOCAL_SRC_FILES := foo-user.cLOCAL_SHARED_LIBRARIES := foo-prebuiltinclude $(BUILD_SHARED_LIBRARY)
Here, LOCAL_MODULE
is the name of the module referring涉及 to the prebuilt; LOCAL_SHARED_LIBRARIES
is the name of the prebuilt, itself.
Exporting Headers for Prebuilt Libraries
The code in foo-user.c
depends on specific declarations that normally reside in a header file, such as foo.h
, distributed with the prebuilt library. For example, foo-user.c
might have a line like the following:
#include <foo.h>
In such a case, you need to provide the header and its include path to the compiler when you build the foo-user
module. A simple way to accomplish完成 this task is to use exports in the prebuilt module definition. For example, as long as header foo.h
is located under the include
directory associated with the prebuilt module, you can declare it as follows:
include $(CLEAR_VARS)LOCAL_MODULE := foo-prebuiltLOCAL_SRC_FILES := libfoo.soLOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/includeinclude $(PREBUILT_SHARED_LIBRARY)
The LOCAL_EXPORT_C_INCLUDES
definition here ensures that the build system exports the path to the prebuilt library's include
directory, prepending that path onto the value of the LOCAL_C_INCLUDES
for the module dependent on it.
This operation allows the build system to find the necessary headers.
Debugging Prebuilt Libraries
We recommend that you provide prebuilt shared libraries containing debug symbols. The NDK build system alwaysstrips the symbols from the version of the library that it installs into $PROJECT/libs/<abi>/
, but you can use the debug version for debugging with ndk-gdb
.
strips
网络释义
n. 条(strip的复数);分割公债,本息拆离;简易机场
v. 剥夺(stirp的三单形式);剥光…的外皮;把…切成细条;剥去;拿走
服装 纸条本息分离债券(Separate Trading Of Registered Interest And Pricipal Securities)
Selecting ABIs for Prebuilt Libraries
You must make sure to select the right version of your prebuilt shared library for your targeted ABI. TheTARGET_ARCH_ABI
variable in the Android.mk
file can point the build system at the appropriate version of the library.
For example, assume that your project contains two versions of library libfoo.so
:
armeabi/libfoo.sox86/libfoo.so
The following snippet片段 shows how to use TARGET_ARCH_ABI
so that the build system selects the appropriate version of the library:
include $(CLEAR_VARS)LOCAL_MODULE := foo-prebuiltLOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfoo.soLOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/includeinclude $(PREBUILT_SHARED_LIBRARY)
If you have specified armeabi
as the value of TARGET_ARCH_ABI
, the build system uses the version oflibfoo.so
located in the armeabi
directory. If you have specified x86
as the value TARGET_ARCH_ABI
, the build system uses the version in the x86
directory.
- android ndk Using Prebuilt Libraries
- android ndk Using Existing Libraries
- android prebuilt
- Using Android Studio to build applications with NDK and Boost C++ libraries
- Building Open Source libraries with Android NDK
- (ZT) Using the Android NDK
- NDK提供的共享库(Prebuilt)
- NDK提供的共享库(Prebuilt)
- NDK提供的共享库(Prebuilt)
- NDK提供的共享库(Prebuilt)
- Import STL libraries to the Android NDK code
- Using Extra Libraries
- Using Dynamic Libraries(Updating)
- Using Dynamic Libraries
- android提供的共享库(Prebuilt)
- 关于Android.mk中PREBUILT的问题
- Android 关于prebuilt编译学习笔记
- Android Libraries
- Linux常用命令
- JavaSE IO流 File文件操作基础知识
- HTTPS概述
- LintCode(158)
- 判断处理器是Big_endian的还是Little——endian的
- android ndk Using Prebuilt Libraries
- hdu 2955 Robberies
- 使用APKTOOL 反编译APK 失败的解决方法
- Hibernate插入、查询、删除操作 HQL
- Hash算法冲突解决方法分析
- 【扣丁学堂】看完惊呆!支付宝是如何用大数据憋死伪基站骗子?
- GIT和SVN之间的五个基本区别
- 一致性 hash 算法( consistent hashing )
- WIN8.1安装USB to UART经验