How to remove all debug logging calls before building the release version of an Android app?

前端 未结 27 1535
有刺的猬
有刺的猬 2020-11-22 07:39

According to Google, I must \"deactivate any calls to Log methods in the source code\" before publishing my Android app to Google Play. Extract from section 3 of th

27条回答
  •  遇见更好的自我
    2020-11-22 08:13

    As zserge's comment suggested,

    Timber is very nice, but if you already have an existing project - you may try github.com/zserge/log . It's a drop-in replacement for android.util.Log and has most of the the features that Timber has and even more.

    his log library provides simple enable/disable log printing switch as below.

    In addition, it only requires to change import lines, and nothing needs to change for Log.d(...); statement.

    if (!BuildConfig.DEBUG)
        Log.usePrinter(Log.ANDROID, false); // from now on Log.d etc do nothing and is likely to be optimized with JIT
    

提交回复
热议问题