Setup

This document explains how to:

  • Get and install the NDK.
  • Configure your system and the Eclipse and the Android Development Tool (ADT) for use with it.
  • Verify, using a simple sample, that everything is working as expected.

This document assumes that you are already familiar with Java-based Android development. For more information on that topic, see the Android developer site.

Installation

To install and configure the NDK, follow these steps:

  1. Get and install the Android SDK.
  2. Download and extract the NDK, making sure to download the correct version for your development platform. You may place the unzipped directory anywhere on your local drive.
  3. Update your PATH environment variable with the location of the directory that contains the NDK.

Configuring Eclipse

Eclipse must know where the NDK is in order to use it when building your app. Follow these steps to set the location of the NDK.

  1. Launch Eclipse, which is installed as part of the Android SDK.
  2. Open Window > Preferences.
  3. In the pane on the left side of the Preferences window, select Android. The Android section expands, revealing a number of subsections.
  4. Select NDK. In the pane on the right side of the Preferences window, browse to the directory that contains the NDK.
  5. Click OK to return to the Package Explorer display.

Verification

Eclipse

To confirm that you have installed the NDK, set it up correctly, and properly configured Eclipse, follow these steps:

  1. Import the hello-jni sample from <ndk>/samples/, as you would any other Android project.
  2. In the Project Explorer pane, right-click the project name (HelloJni). A context menu appears.
  3. From the context menu, select Android Tools > Add Native Support. The Add Android Native Support window appears.
  4. Accept the default library name (“hello-jni”), and click Finish.
  5. Build and execute the application.

Command line

Follow these steps to build from the command line:

  1. Change to the root directory of your project.
  2. Execute ndk-build to build the native component of your app. do this by typing ndk-build at the command prompt.
  3. Build and install your project as you would a regular Android app written in Java. For more information, see Building and Running and Building and Running from the Command Line.

If you have successfully installed and configured the NDK, the screen on your target device looks as shown in Figure 1.

Output: Hello from JNI!

Figure 1. Target-device screen after successful launch.