NDK how to remove Log Debug statements on release
android, android-ndk, c++, debugging
Solution
Use the `NDEBUG` macro. Or you could really `#ifdef` on anything.
#ifdef NDEBUG
#define LOGD(...)
#else
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#endif
Then for the code:
void f()
{
LOGD("About to do some stuff");
doSomeStuff();
}
The compiler will see (roughly - `ANDROID_LOG_DEBUG` and `LOG_TAG` will also be replaced with their values if they are macros):
void f()
{
__android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,"About to do some stuff");
doSomeStuff();
}
when `NDEBUG` is undefined and will see:
void f()
{
;
doSomeStuff();
}
when `NDEBUG` is defined.
Problem
I know using proguard you can remove java Log.d debug statements from release versions https://stackoverflow.com/a/13327603/1527440 But is there way to remove log debug statements from NDK C/C++ code. I am using a define statement to call them in NDK ``` #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) ```