Chapter 18. The Android Native Development Kit (NDK)

Java Native Interface (JNI) is a part of the Java standard that enables developers to write native methods in other languages, such as C and C++, and call those methods from Java code. This is especially useful when you want to use platform-specific features or take advantage of hardware in the platform, such as achieving faster numerical computation by taking advantage of FPU instruction set extensions, or letting graphics-intensive code exploit the OpenGL API. This chapter covers JNI basics for programmers using the Android NDK. For further details, see the Java Native Interface Specification.

Typical good candidates for implementation in C or C++ using the NDK are self-contained, CPU-intensive operations that don’t allocate much memory, such as signal processing, physics simulation, and so on. Simply recoding a random method to run in C usually does not result in a large performance increase. When examining whether you should develop in native code, think about your requirements and see whether the Android SDK already provides the functionality you need. You’ll find that in most cases the Android SDK will fulfill your needs. It is worth remembering that, although most Android platforms are ARM right now, there are likely to be others (such as Atom) in the future. Using NDK makes your code nonportable.

JNI is what Android uses to access code implemented in C or C++, and the Android NDK is an optional extension to the Android SDK ...

Get Programming Android now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.