It took me a while to figure out how to make the Android NDK working with CMake generated makefiles.
Recently I’m trying to port my simple test of character animation with Assimp Library on Android NDK so I needed to build an Assimp version for Android ARM CPU.
I could not find any infos on this topic on the net and officially, it seems that Assimp Library only supports iOS devices.
So I’ve experimented quite a bit and finally I come up with a solution!
Before we start, I have to say that I’ve tested my solution on OSX and probably it will work on Linux too but I seriously doubt that it will work on Windows + cygwin. You have been warned! 😀
Here we go!
1. Set up an Android Standalone Toolchain
Extract the downloaded Android NDK archive wherever you want (mine is ~/android-ndk-r8b)
Enter into this directory:
Fromt there run this command:
sh make-standalone-toolchain.sh –platform=android-8 –ndk-dir=/Users/prometheus/android-ndk-r8b –install-dir=/Users/prometheus/android-toolchain –toolchain=arm-linux-androideabi-4.4.3
Now you should have a new directory called android-toolchain.
2. Download the Anroid CMake configuration file
Inside the directory where you have android-ndk-r8b and android-toolchain directories, run this command:
hg clone https://android-cmake.googlecode.com/hg/ android-cmake
Now you should have these three directories: android-ndk-r8b, android-toolchain and android-cmake
3. Setup the needed Environment Variables
Edit your .profile file (if you don’t have it, just create it) as follows:
4. Test CMake
Go inside this directory:
There run this commands:
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDTOOLCHAIN ..
It should build libhello-cmake.so inside ~/android-cmake/samples/hello-cmake-test/libs/armeabi-v7a
And that’s it!
As you’ve probably noticed, we have specified which GCC version we need to use by adding the argument –toolchain=arm-linux-androideabi-4.4.3
At the time of this writing, this is mandatory because if you try to use CMake with GCC-4.6 it won’t work!