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.
Download the Android NDK and extract it:
tar -xf android-ndk-r9-linux-x86_64.tar.bz2 cd android-ndk-r9
Download the toolchain source code:
./build/tools/download-toolchain-sources.sh src
The script will automatically download sources for the most recent NDK release (not the tip of the tree).
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
This should be enough to build the Linux version of the toolchain:
./build/tools/build-gcc.sh --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.
Windows
To build the Windows version of the toolchain, a few extra steps will be needed.
Install MinGW:
sudo apt-get install curl sudo apt-get install subversion # Required for 32-bit ./build/tools/build-mingw64-toolchain.sh --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/build-mingw64-toolchain.sh --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
Clone the repositories containing the necessary prebuilt items:
# Required for 32-bit git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6 $(pwd)/../prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6 # Required for 64-bit git clone https://android.googlesource.com/platform/prebuilts/tools $(pwd)/../prebuilts/tools git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6 $(pwd)/../prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6
Install the following required package:
sudo apt-get install lib32z1-dev
Now, both the 32-bit and 64-bit Windows version of the NDK toolchain can be built:
# 32-bit ./build/tools/build-gcc.sh --verbose --mingw $(pwd)/src $(pwd) arm-linux-androideabi-4.6 # 64-bit ./build/tools/build-gcc.sh --verbose --mingw --try-64 $(pwd)/src $(pwd) arm-linux-androideabi-4.6
References:
- http://www.roman10.net/build-android-ndk-toolchain-from-source-code/
- http://glandium.org/blog/?p=2146