How to detect compilation by Android NDK in a C/C++ file?

Rémi picture Rémi · Jun 16, 2011 · Viewed 30.8k times · Source

Is there a preprocessor macro that will let me know NDK is compiling my code? I could manually define my own, but I'd rather not if possible.

Answer

chvor picture chvor · Dec 13, 2011

It is #ifdef __ANDROID__ as seen by running the preprocessor:

~$ /usr/local/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -E -dM - < /dev/null | grep -i android

The output is:

#define __ANDROID__ 1

No need to depend on defining stuff in your project especially if you're skipping the NDK build system.