Using the Android Native Development Kit (NDK)

version 1.3

Introduction

The Android Native Development Kit enables developers to write shared libraries in C or C++ and call them from Java code. The native shared libraries can be packaged into apk files along with a normal Android application written in Java, so that the resulting Android application can be downloaded and installed on an Android phone.

The Native Development Kit consists of:

The Native Development Kit is designed to be used with the Android SDK:

Setting up your machine

The Native Development Kit may be installed on either Linux or OS X. Developing under Windows is not yet supported.

Linux Installation

The Android build is routinely tested on recent versions of Ubuntu (6.06 and later), but may work on other distributions as well.

Ubuntu Linux (i386)

To set up your Linux development environment, make sure you have the following:
  • Git 1.5.4 or newer
$ sudo apt-get install git-core

Ubuntu Linux (amd64)

This has not been as well tested.

The Android build requires a 32-bit build environment:
  • Get the packages as listed above in the i386 instructions:   
sudo apt-get install git-core

Other Linux

There's no reason why Android cannot be built on non-Ubuntu systems. In general you will need:

Mac OS Installation


Installing the Android SDK

The Android NDK uses the Android SDK. You can find the Android SDK at http://code.google.com/android/download.html
This version of the Android NDK requires the Cupcake version of the Android SDK.

Installing the Prebuilt Native Toolchain

The NDK uses the prebuilt native toolchain from the Android Open Source git repository.

To download the prebuilt native toolchain to your working directory, execute the following commands:

git clone git://android.git.kernel.org/platform/prebuilt.git
cd prebuilt
git checkout -b cupcake -t origin/cupcake

Setting Environment Variables

The NDK requires that you set two environment variables:
  • PREBUILT must be set to the directory that contains the prebuilt toolchain. Include the "prebuilt" directory in the path. Example: /Volumes/android/prebuilt
  • ANDROID_SDK_BASE must be set to the directory that contains the Android SDK. Example: ~/AndroidSDK

Unpacking the NDK

Unpack the android_pndk.tar.gz into your working directory

tar -zxvf android_pndk.tar.gz

This will create a directory called pndk. It should contain a README.html file (this file) and the following directories: config, include, lib, and sample.

Look in the "samples" directory for samples showing how to use the NDK.