NDK如何删除发布上记录调试声明 [英] NDK how to remove Log Debug statements on release

查看:182
本文介绍了NDK如何删除发布上记录调试声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用ProGuard,你可以删除发行版本的Java Log.d调试语句
<一href=\"http://stackoverflow.com/a/13327603/1527440\">http://stackoverflow.com/a/13327603/1527440

但是,有没有办法去除NDK C / C ++ code日志调试语句。

我使用的是定义语句来调用它们NDK

 的#define LOGD(...)__android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__ VA_ARGS__)


解决方案

使用 NDEBUG 宏。或者你可以真正的 #IFDEF 上的任何东西。

  #IFDEF NDEBUG#定义LOGD(...)#其他#定义LOGD(...)__android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__ VA_ARGS__)#万一

然后为code:

 无效F()
{
    LOGD(关于做一些东西);
    doSomeStuff();
}

编译器会看到(约 - ANDROID_LOG_DEBUG LOG_TAG 也将与他们的价值观,如果他们是宏替换):

 无效F()
{
    __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,关于做一些东西);
    doSomeStuff();
}

NDEBUG 是不确定的,会看到:

 无效F()
{
    ;
    doSomeStuff();
}

NDEBUG 定义。

I know using proguard you can remove java Log.d debug statements from release versions http://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__) 

解决方案

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.

这篇关于NDK如何删除发布上记录调试声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆