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

前端 未结 27 1536
有刺的猬
有刺的猬 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:32

    I highly suggest using Timber from Jake Wharton

    https://github.com/JakeWharton/timber

    it solves your issue with enabling/disabling plus adds tag class automagically

    just

    public class MyApp extends Application {
    
      public void onCreate() {
        super.onCreate();
        //Timber
        if (BuildConfig.DEBUG) {
          Timber.plant(new DebugTree());
        }
        ...
    

    logs will only be used in your debug ver, and then use

    Timber.d("lol");
    

    or

    Timber.i("lol says %s","lol");
    

    to print

    "Your class / msg" without specyfing the tag

提交回复
热议问题