Book Image

Mastering Android NDK

Book Image

Mastering Android NDK

Overview of this book

Android NDK is used for multimedia applications that require direct access to system resources. NDK is also the key for portability, which in turn allows a reasonably comfortable development and debugging process using familiar tools such as GCC and Clang toolchains. This is a hands-on guide to extending your game development skills with Android NDK. The book takes you through many clear, step-by-step example applications to help you further explore the features of Android NDK and some popular C++ libraries and boost your productivity by debugging the development process. Through the course of this book, you will learn how to write portable multi-threaded native code, use HTTP networking in C++, play audio files, use OpenGL ES 3, and render high-quality text. Each chapter aims to take you one step closer to building your application. By the end of this book, you will be able to create an engaging, complete gaming application.
Table of Contents (17 chapters)
Mastering Android NDK
About the Authors
About the Reviewers

Using Android command-line tools on OS X

Installation of Android development tools on OS X is straightforward. First of all, you will need to download the required official SDK and NDK packages from As we are going for command-line tools, we can use the SDK Tools Only package available at As for the NDK, OS X Yosemite works with the 64-bit Android NDK, which can be downloaded from

We will install all these tools into the user's home folder; in our case, it is /Users/sk.

To get Apache Ant and Gradle, the best way would be to install the package manager Homebrew from and bring in the required tools using the following commands:

$ brew install ant
$ brew install gradle

This way you will not be bothered with installation paths and other low-level configuration stuff. The following are the steps to install packages and set path for them:


Since the notion of this book is doing stuff from the command line, we will indeed do so the hard way. However, you are encouraged to actually visit the download page,, in your browser and check for updated versions of the Android SDK and NDK.

  1. Download the Android SDK for OS X from the official page and put it into your home directory:

    >curl -o
  2. Unpack it:

  3. Then, download the Android NDK. It comes as a self-extracting binary:

    >curl -o android-ndk-r10e.bin
  4. So, just make it executable and run it:

    >chmod +x android-ndk-r10e.bin
  5. The packages are in place. Now, add paths to your tools and all the necessary environment variables to the .profile file in your home directory:

    export PATH=/Users/sk/android-ndk-r10e:/Users/sk/android-ndk-r10e/prebuilt/darwin-x86_64/bin:/Users/sk/android-sdk-macosx/platform-tools:$PATH
  6. Use these variables within Android scripts and tools:

    export NDK_ROOT="/Users/sk/android-ndk-r10e"
    export ANDROID_SDK_ROOT="/Users/sk/android-sdk-macosx"
  7. Edit the file to set up the paths on a per-project basis.