Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NDK how to remove Log Debug statements on release

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__) 
like image 368
pt123 Avatar asked Jul 29 '13 22:07

pt123


1 Answers

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.

like image 182
Joel Avatar answered Nov 16 '22 21:11

Joel