The Android NDK is a companion tool to the Android SDK that lets you build performance-critical portions of your apps in native code. It provides headers and libraries that allow you to build activities, handle user input, use hardware sensors, access application resources, and more, when programming in C or C++. If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device. The fundamental Android application model does not change.
Why use Android NDK ?
Using native code does not result in an automatic performance increase, but always increases application complexity. If you have not run into any limitations using the Android framework APIs, you probably do not need the NDK.
The NDK will not benefit most applications. As a developer, you need to balance its benefits against its drawbacks; notably, using native code does not result in an automatic performance increase, but always increases application complexity. In general, you should only use native code if it is essential to your application, not just because you prefer to program in C/C++.
Typical good candidates for the NDK are self-contained, CPU-intensive operations that don't allocate much memory, such as signal processing, physics simulation, and so on. Simply re-coding a method to run in C usually does not result in a large performance increase. When examining whether or not you should develop in native code, think about your requirements and see if the Android framework APIs provide the functionality that you need. The NDK can, however, can be an effective way to reuse a large corpus of existing C/C++ code.
The Android framework provides two ways to use native code:
System Requirements for Android NDK Installation
The NDK is designed for use only in conjunction with the Android SDK. If you have not already installed and setup the Android SDK, please do so before downloading the NDK.
The Android SDK
- A complete Android SDK installation (including all dependencies) is required.
- Android 1.5 SDK or later version is required.
Supported operating systems for Android NDk
- Windows XP (32-bit) or Vista (32- or 64-bit)
- Mac OS X 10.4.8 or later (x86 only)
- Linux (32 or 64-bit; Ubuntu 8.04, or other Linux distributions using GLibc 2.7 or later)
Required development tools for Android NDK
- For all development platforms, GNU Make 3.81 or later is required. Earlier versions of GNU Make might work but have not been tested.
- A recent version of awk (either GNU Awk or Nawk) is also required.
- For Windows, Cygwin 1.7 or higher is required. The NDK will not work with Cygwin 1.5 installations.
The NDK provides:
- A set of tools and build files used to generate native code libraries from C and C++ sources
- A way to embed the corresponding native libraries into an application package file (.apk) that can be deployed on Android devices.
- A set of native system headers and libraries that will be supported in all future versions of the Android platform, starting from Android 1.5. Applications that use native activities must be run on Android 2.3 or later.
- Documentation, samples, and tutorial
The latest release of the NDK supports the following instruction sets:
- ARMv5TE (including Thumb-1 instructions)
- ARMv7-A (including Thumb-2 and VFPv3-D16 instructions, with optional support for NEON/VFPv3-D32 instructions)
- x86 instructions (see CPU-ARCH-ABIS.HTML for more information)
ARMv5TE machine code will run on all ARM-based Android devices.
ARMv7-A will run only on devices such as the Verizon Droid or Google Nexus One that have a compatible CPU.
The main difference between the two instruction sets is that ARMv7-A supports hardware FPU, Thumb-2, and NEON instructions. You can target either or both of the instruction sets — ARMv5TE is the default, but switching to ARMv7-A is as easy as adding a single line to the application's Application.mk file, without needing to change anything else in the file. You can also build for both architectures at the same time and have everything stored in the final .apk. Complete information is provided in the CPU-ARCH-ABIS.HTML in the NDK package.
The NDK provides stable headers for libc (the C library), libm (the Math library), OpenGL ES (3D graphics library), the JNI interface, and other libraries, as listed in the Development Tools section.
The NDK includes a set of cross-toolchains (compilers, linkers, etc..) that can generate native ARM binaries on Linux, OS X, and Windows (with Cygwin) platforms.
It provides a set of system headers for stable native APIs that are guaranteed to be supported in all later releases of the platform:
- 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
The NDK also provides a build system that lets you work efficiently with your sources, without having to handle the toolchain/platform/CPU/ABI details. You create very short build files to describe which sources to compile and which Android application will use them — the build system compiles the sources and places the shared libraries directly in your application project.
NOTE: With the exception of the libraries listed above, native system libraries in the Android platform are not stable and may change in future platform versions. Your applications should only make use of the stable native system libraries provided in this NDK.
Sample applications code and documentation is also included in package.
Android NDK Old Versions
Following are the Android NDK releases to date starting from June 2009
Android NDK, Revision 7 (November 2011)
Android NDK, Revision 6b (August 2011)
Android NDK, Revision 6 (July 2011)
Android NDK, Revision 5c (June 2011)
Android NDK, Revision 5b (January 2011)
Android NDK, Revision 5 (December 2010)
Android NDK, Revision 4b (June 2010)
Android NDK, Revision 3 (March 2010)
Android NDK, Revision 2 (September 2009)
Android NDK, Revision 1 (June 2009)
|