Reputation: 28860
I have a native library I build that needs to be build in the Android build, but can also be built using the NDK. How can I distinguish using the preprocessor between NDK build and Android build.
#ifdef __ANDROID__
#ifdef NDK ??? // does ndk export some symbols I can use here ?
foo();
#else // Android tree build
foo2();
#endig
#endif // __ANDROID__
Upvotes: 0
Views: 484
Reputation: 21183
I would use one of the platform build environment variables to distinguish two builds. That could be DEVICE_NAME
, TARGET_DEVICE
, PLATFORM_VERSION
or anything else that's defined beyond my project's scope. And, depending on that environment variable, I'd define a flag in my project's Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo
ifeq ($(DEVICE_NAME),)
# no device name is defined, got to be an NDK build
LOCAL_CFLAGS := -DANDROID_NDK
endif
and then in foobar.c
#ifdef ANDROID_NDK
foo();
#else
foo2();
Upvotes: 2