Skip to content

Most visited

Recently visited

navigation

Setup Eclipse (DEPRECATED)

The Eclipse ADT plugin is no longer supported. We recommend migrating to Android Studio to compile, build, and package your app's native sources using ndk-build or CMake. Compatibility with ndk-build makes it easy to migrate your native projects from Eclipse to Android Studio. To learn more about native development with the official IDE for Android, read Add C and C++ Code to Your Project.

Installation

To install and configure the NDK, follow these steps:

  1. Get and install the Android SDK command line tools.
  2. Download 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 Configure Your Build and Run Gradle 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.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)