How to detect compilation by Android NDK in a C/C++ file?
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.
Short answer: #ifdef ANDROID
.
The ANDROID
macro is defined for you in build-module.mk (part of the standard build system):
# always define ANDROID when building binaries
#
LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS)