Recently, I've had to build a custom Android NDK toolchain from source. The steps below detail my approach. I used a fresh install of Ubuntu 12.04 64-bit in a virtual machine with 6GB of RAM and a large amount of disk space, in conjuction with NDK r9.

  1. Download the Android NDK and extract it:

    tar -xf android-ndk-r9-linux-x86_64.tar.bz2
    cd android-ndk-r9
  2. Download the toolchain source code:

    ./build/tools/ src

    The script will automatically download sources for the most recent NDK release (not the tip of the tree).

  3. Install the following required packages:

    sudo apt-get install g++-multilib
    sudo apt-get install m4
    sudo apt-get install texinfo
    sudo apt-get install bison
    sudo apt-get install flex
    sudo apt-get install libncurses5-dev
    sudo apt-get install lib32ncurses5-dev
  4. This should be enough to build the Linux version of the toolchain:

    ./build/tools/ --verbose $(pwd)/src $(pwd) arm-linux-androideabi-4.6

    Depending on how powerful your machine is, the build can take anywhere from a few minutes to an hour plus.


To build the Windows version of the toolchain, a few extra steps will be needed.

  1. Install MinGW:

    sudo apt-get install curl
    sudo apt-get install subversion
    # Required for 32-bit
    ./build/tools/ --target-arch=i686
    # Required for 64-bit. The --force-build argument is not specific
    # to 64-bit; it's needed to ensure the sources are actually
    # built the second time the command is run.
    ./build/tools/ --force-build
    cp -a /tmp/build-mingw64-toolchain-$USER/install-x86_64-linux-gnu/i686-w64-mingw32 ~/
    cp -a /tmp/build-mingw64-toolchain-$USER/install-x86_64-linux-gnu/x86_64-w64-mingw32 ~/
    export PATH=$PATH:~/i686-w64-mingw32/bin
    export PATH=$PATH:~/x86_64-w64-mingw32/bin
  2. Clone the repositories containing the necessary prebuilt items:

    # Required for 32-bit
    git clone $(pwd)/../prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6
    # Required for 64-bit
    git clone $(pwd)/../prebuilts/tools
    git clone $(pwd)/../prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6
  3. Install the following required package:

    sudo apt-get install lib32z1-dev
  4. Now, both the 32-bit and 64-bit Windows version of the NDK toolchain can be built:

    # 32-bit
    ./build/tools/ --verbose --mingw $(pwd)/src $(pwd) arm-linux-androideabi-4.6
    # 64-bit
    ./build/tools/ --verbose --mingw --try-64 $(pwd)/src $(pwd) arm-linux-androideabi-4.6