Use precompiled libraries
NDK supports the use precompiled libraries (supports both static and shared libraries). This function has two main use cases:
- Distribute your own library NDK to third party developers (and not distribute your source code).
- Use your own library of pre-compiled version to improve the compilation speed.
This page explains how to use precompiled libraries.
Statement precompiled libraries
Precompiled libraries for each statement you must use your own as a separate module. To do this, follow these steps:
- Provide a name for the module. This name is not necessarily the same name precompiled library itself.
- In the module
Android.mk
file, the path to the precompiled libraries provide you assigned toLOCAL_SRC_FILES
. SpecifyLOCAL_PATH
the relative value of the variable path.Note : Be sure to select a pre-compiled version of the library with your target corresponding to the ABI. To learn more about how to ensure that the library supports ABI, please refer to choose ABI precompiled libraries .
- According to you are using a shared library (
.so
) or static library (.a
), addPREBUILT_SHARED_LIBRARY
orPREBUILT_STATIC_LIBRARY
.
The following example assumes that small pre-compiled libraries libfoo.so
and describe its Android.mk
file in the same directory.
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := foo-prebuilt LOCAL_SRC_FILES := libfoo.so include $(PREBUILT_SHARED_LIBRARY)
In this example, the same module name and the name of a precompiled library.
You will be compiled shared library of pre-compiled copies placed $PROJECT/obj/local
in, and a copy will be another extract debug information is placed $PROJECT/libs/<abi>
in. Here $PROJECT
is the root directory of your project.
References from other modules pre-compiled libraries
References from other modules pre-compiled library, in the modules associated with these Android.mk
files, the name of the precompiled libraries designated LOCAL_STATIC_LIBRARIES
or LOCAL_SHARED_LIBRARIES
variable.
For example, using libfoo.so
the module may be similar to the following instructions:
include $(CLEAR_VARS) LOCAL_MODULE := foo-user LOCAL_SRC_FILES := foo-user.c LOCAL_SHARED_LIBRARIES := foo-prebuilt include $(BUILD_SHARED_LIBRARY)
Here LOCAL_MODULE
is a reference name of the module precompiled libraries; LOCAL_SHARED_LIBRARIES
precompiled library name itself.
Export precompiled headers library
foo-user.c
The code is typically located depends on the header file (e.g., foo.h
a specific statement) in, and the header file is allocated using a precompiled library. For example, foo-user.c
there may be a line of code similar to the following:
#include <foo.h>
In this case, if you compile a foo-user
module, you need to provide a point to include headers and their path compiler. A simple way to do this is to use the Export content in pre-compiled module definition. For example, as long as the header foo.h
is located associated with the pre-compiled modules include
directory, you can be declared in the following manner:
include $(CLEAR_VARS) LOCAL_MODULE := foo-prebuilt LOCAL_SRC_FILES := libfoo.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY)
Here's LOCAL_EXPORT_C_INCLUDES
the definition of the compiler system will ensure that export point to the precompiled libraries include
directory path for the module depends on its path to additional LOCAL_C_INCLUDES
value.
This system allows the compiler to find the necessary header.
Debug precompiled libraries
We recommend that you provide pre-compiled shared library that contains debugging symbols. NDK build system from installation to always $PROJECT/libs/<abi>/
extracted symbols that version of the library, but you can use the debug version by ndk-gdb
debugging.
Select ABI precompiled libraries
Be sure to select the correct version of the shared library of pre-compiled for your target ABI. Android.mk
File TARGET_ARCH_ABI
variables can be compiled versions of the system point to the appropriate library.
For example, suppose your project contains libraries libfoo.so
of the following two versions:
armeabi/libfoo.so x86/libfoo.so
The following code snippet shows how to use TARGET_ARCH_ABI
, in order to compile the system to select the appropriate version of the library:
include $(CLEAR_VARS) LOCAL_MODULE := foo-prebuilt LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfoo.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY)
If you armeabi
specified as TARGET_ARCH_ABI
the value, the compiler will use the system located in armeabi
the directory libfoo.so
version. If you x86
specified as TARGET_ARCH_ABI
the value, the compiler will use the system x86
directory version.