android ndk是android用于开发本地代码的开发工具包。它提供C/C++交叉编译工具。android内核、驱动、已有的C/C++代码,都需要ndk来支持开发。
目前支持以下平台:arm、mpis、x86
- ARMv5TE, including Thumb-1 instructions (see
docs/CPU-ARCH-ABIS.html
for moreinformation) - ARMv7-A, including Thumb-2 and VFPv3-D16 instructions, with optional support for NEON/VFPv3-D32 instructions (see
docs/CPU-ARM-NEON.html
for more information) - x86 instructions (see
docs/CPU-X86.html
for more information) - MIPS instructions (see
docs/CPU-MIPS.html
for more information)
官网:http://developer.android.com/tools/sdk/ndk/index.html
下载:http://developer.android.com/tools/sdk/ndk/index.html
解压:
k@k-C410:/data/android-ndk-r9$ ls
build ndk-build.cmd ndk-gdb-py.cmd README.TXT toolchains
docs ndk-depends ndk-stack RELEASE.TXT
documentation.html ndk-gdb ndk-which samples
GNUmakefile ndk-gdb-py platforms sources
ndk-build ndk-gdb.py prebuilt tests
设置环境变量:
linux下:
export ANDROID_NDK=/data/android-ndk-r9
export PATH=$PATH:$ANDROID_NDK
windows下:
可以配合cygwin使用,配合cygwin使用时,和linux一样。
如果单独使用:
需要把安装目录加入到环境变量PATH中。
ndk内容:
ndk-build:工程管理脚本工具,google自己搞的与automake类似的东东。
- 在应用程序开发中,把本地代码放到工程的jni目录下:
<project>/jni/
- 建立
<project>/jni/Android.mk
用于描述编译 - 可选:
建立<project>/jni/Application.mk
. - 用ndk-build脚本编译本地代码:
cd <project>
<ndk>/ndk-build - 完成后,用普通的sdk编译方法,sdk工具会把本地代码打包进apk中。
platforms :android平台系统的库和头文件
k@k-C410:/data/android-ndk-r9/platforms/android-14/arch-arm/usr/lib$ ls
crtbegin_dynamic.o libc.a libjnigraphics.so libstdc++.a
crtbegin_so.o libc.so liblog.so libstdc++.so
crtbegin_static.o libdl.so libm.a libthread_db.so
crtend_android.o libEGL.so libm.so libz.so
crtend_so.o libGLESv1_CM.so libOpenMAXAL.so
libandroid.so libGLESv2.so libOpenSLES.so
- libc (C library) headers
- libm (math library) headers
- JNI interface headers
- libz (Zlib compression) headers
- liblog (Android logging) header
- OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers
- libjnigraphics (Pixel buffer access) header (for Android 2.2 and above).
- A Minimal set of headers for C++ support
- OpenSL ES native audio libraries
- Android native application APIS
toolchains:c/c++交叉编译工具
k@k-C410:/data/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin$ ls
arm-linux-androideabi-addr2line arm-linux-androideabi-gprof
arm-linux-androideabi-ar arm-linux-androideabi-ld
arm-linux-androideabi-as arm-linux-androideabi-ld.bfd
arm-linux-androideabi-c++ arm-linux-androideabi-ld.gold
arm-linux-androideabi-c++filt arm-linux-androideabi-ld.mcld
arm-linux-androideabi-cpp arm-linux-androideabi-nm
arm-linux-androideabi-elfedit arm-linux-androideabi-objcopy
arm-linux-androideabi-g++ arm-linux-androideabi-objdump
arm-linux-androideabi-gcc arm-linux-androideabi-ranlib
arm-linux-androideabi-gcc-4.8 arm-linux-androideabi-readelf
arm-linux-androideabi-gcc-ar arm-linux-androideabi-run
arm-linux-androideabi-gcc-nm arm-linux-androideabi-size
arm-linux-androideabi-gcc-ranlib arm-linux-androideabi-strings
arm-linux-androideabi-gcov arm-linux-androideabi-strip
arm-linux-androideabi-gdb
sources:源文件,包括c++stl。
k@k-C410:/data/android-ndk-r9/sources/cxx-stl$ ls
gabi++ gnu-libstdc++ stlport system
docs:文档
samples:例子代码