- The Android NDK is not a single tool; it is a comprehensive set of APIs, cross-compilers, linkers, debuggers, build tools, documentation, and sample applications. The following are some of the key components of Android NDK:
- ARM, x86, and MIPS cross-compilers
- Build system
- Java Native Interface headers
- C library
- Math library
- POSIX threads
- Minimal C++ library
- ZLib compression library
- Dynamic linker library
- Android logging library
- Android pixel buffer library
- Android native application APIs
- OpenGL ES 3D graphics library
- OpenSL ES native audio library
- OpenMAX AL minimal support
- Build system
- The primary goal of this build system is to allow developers to only write very short build files to describe their native Android applications; the build system handles many details including the toolchain, platform, CPU,and ABI specifics on behalf of the developer。
- the Android NDK build system relies on two other files that are expected to be provided by the developer as a part of the NDK project: Android.mk and Application.mk
-
- Android.mk---a makefile用来将本NDK 工程“描述”到Android NDK build system。该文件是由developer提供的,放在工程的jni目录下,Android NDK build system只会从该目录下寻找该文件。
- build a shared library #let android build system to locate the source file;
#call my-dir是通过调用MACRO来动态获取路径,而不是通过写死(hard-coded)
LOCAL_PATH := $(call my-dir)
#删除文件,避免冲突
include $(CLEAR_VARS)
#指定生成module的名字,如hello-jni.so
LOCAL_MODULE := hello-jni
#指定要生成module而需要进行build的源文件
#这里只需要一个源文件,当需要多个源文件时,各个文件之间用空格隔开
LOCAL_SRC_FILES := hello-jni.c
#UILD_SHARED_LIBRARYvariable is set by the Android NDK build system to the location of build-shared-library.mkfile
include $(BUILD_SHARED_LIBRARY) - build multiple shared library LOCAL_PATH := $(call my-dir)
#
# Module 1
#
include $(CLEAR_VARS)
LOCAL_MODULE := module1
LOCAL_SRC_FILES := module1.c
include $(BUILD_SHARED_LIBRARY)
#
# Module 2
#
include $(CLEAR_VARS)
LOCAL_MODULE := module2
LOCAL_SRC_FILES := module2.c
include $(BUILD_SHARED_LIBRARY) - build static library--->Static libraries can be used to build shared libraries. For example, when integrating third party code into an existing native project, instead of including the source code directly, the third party code can be compiled as a static library and then combined into the shared library.LOCAL_PATH := $(call my-dir)
#
# the 3rd party AVI library
#
include $(CLEAR_VARS)
LOCAL_MODULE := avilib
LOCAL_SRC_FILES := avilib.c platform_posix.c
include $(BUILD_STATIC_LIBRARY)
#
# Native module
#
include $(CLEAR_VARS)
LOCAL_MODULE := module
LOCAL_SRC_FILES := module.c
LOCAL_STATIC_LIBRARIES := avilib
include $(BUILD_SHARED_LIBRARY) -
- build a shared library
- Application.mk--->一个可选的makefile,位于jni目录下,用来描述 一个application需要使用哪些modules
- 是
nkd-build script--->位于android ndk安装路径下,但执行时要切换到所要编译的project根目录下。该脚本通过传入一些参数来控制盒维护编译过程。
- 常用参数或命令
- -C :默认情况下,ndk-build script要在project根目录下执行,但可以通过使用“-C”选项,显示地指定NDK project的路径
- -B :unconditionally make all targets 无条件地编译所有目标,无论是否有源文件被修改
- -j :nkd-build是调用make进行build,默认情况下make一次只执行一条命令,在带-j选项时,make可以并行处理多条指令(应该是利用了cpu多核的特性吧)
- ndk-build clean : 删除build过程中生成的二进制文件。
-