Before you start
One of the motivations for exploring the NDK in the first place is the opportunity to leverage open source projects, many of which are written in C. After completing this tutorial, you will have learned how to create a Java Native Interface (JNI) library, written in C and compiled with the Native Development Kit (NDK), and incorporate the library into an Android application written in the Java language. The application demonstrates how to perform basic image processing operations against raw image data. You will also learn how to extend the Eclipse build environment to integrate an NDK project into an Android SDK project file. From this foundation, you will be better equipped to port existing open source code to the Android platform.
This tutorial introduces the Android NDK within the Eclipse environment. The NDK is used to add functionality to an Android application using the C programming language. The tutorial begins with a high-level look at the NDK and its common usage scenarios. From there, the topic of image processing is introduced, followed by an introduction and demonstration of this tutorial's application: IBM Photo Phun. This application is a mix of SDK-based Java code and NDK-compiled C code. The tutorial moves on to introduce the Java Native Interface (JNI), which is the technology of interest when working with the NDK. A look ahead to the completed project's source files provides a roadmap for the application constructed here. Then, in a step-by-step manner, you will construct this application. The Java class and C source files are explained. To conclude, the Eclipse build environment is customized to integrate the NDK tool chain directly into the easy-to-use Eclipse build process.
To follow this tutorial, you should be comfortable constructing Android applications with the Android SDK and have a basic familiarity with the C programming language. In addition, you will need the following:
- Eclipse and Android Developer Tools (ADT) — Primary code editor, Java Compiler, and Android Development Tools Plug-in
- Android Software Developer Kit (SDK)
- Android Native Developer Kit (NDK)
- PNG Image — Image used for testing image processing operations
I created the code samples for this tutorial on a MacBook Pro with Eclipse V3.4.2 and Android SDK V8, which supports the Android release labeled 2.2 (Froyo). The NDK release used in this tutorial is r4b. The code requires version r4b or later because the image handling capabilities of the Android NDK are not available in prior releases of the NDK.
See Resources for links to these tools.