Search code examples
androidpreprocessorandroid-ndk

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


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.


Solution

  • 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.