Cross-compiling with Android

Step 0: Download the Android NDK

Download the Android NDK. Then set the ANDROID_NDK_HOME env to the dir that you unzipped the NDK.

Step 1: Create Android Toolchain

Read about how to create the Android Standalong Toolchain. You will likely create the toolchain with a command like this:

$ANDROID_NDK_HOME/build/tools/ --arch=arm --platform=android-19 --install-dir=/tmp/my-android-toolchain

Step 2: Create a Meson cross build file

A Meson cross build file tells the Meson build system details about the nature of the cross compile job you will be performing. My cross compile file looks like this:


name = 'android'  
c = '/tmp/my-android/arm-linux-androideabi/bin/gcc'  
cpp = '/tmp/my-android/arm-linux-androideabi/bin/g++'  
ar = '/tmp/my-android/arm-linux-androideabi/bin/ar'  
ld = '/tmp/my-android/arm-linux-androideabi/bin/ld'  
strip = '/tmp/my-android/arm-linux-androideabi/bin/strip'

root = '/tmp/my-android/'  

Note: the /tmp/my-android/ prefix is where I installed the Android toolchain

Step 3: Invoke Meson

mkdir android-arm-build  
meson android-arm-build --cross-file android_cross.txt  

Step 4: Compile

cd android-arm-build  

Paul Soucy

Read more posts by this author.