are Android's debug logs really stripped at runtime?

前端 未结 3 1391
半阙折子戏
半阙折子戏 2021-02-13 19:41

Android documentation ( http://developer.android.com/reference/android/util/Log.html ) says:

Verbose should never be compiled into an application except d

相关标签:
3条回答
  • 2021-02-13 20:16

    No. You have to do this yourself. You can make your own Log.d wrapper like this:

    public static void debug(String tag, String msg) {
        if (BuildConfig.DEBUG) {
            Log.d(tag, msg);
        }
    }
    
    0 讨论(0)
  • 2021-02-13 20:34

    The best way to remove logs is probably achieved with ProGuard

    Check this question 'Android Proguard, removing all Log statements and merging packages'

    0 讨论(0)
  • 2021-02-13 20:35

    This issue was reported here and a solution was provided in ADT 17.0.0 in Mar 2012

    Added a feature that allows you to run some code only in debug mode. Builds now generate a class called BuildConfig containing a DEBUG constant that is automatically set according to your build type. You can check the (BuildConfig.DEBUG) constant in your code to run debug-only functions.

    0 讨论(0)
提交回复
热议问题