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

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

    Logs can be removed using bash in linux and sed:

    find . -name "*\.java" | xargs sed -ri ':a; s%Log\.[ivdwe].*\);%;%; ta; /Log\.[ivdwe]/ !b; N; ba'
    

    Works for multiline logs. In this solution you can be sure, that logs are not present in production code.

    0 讨论(0)
  • 2020-11-22 08:25

    This is what i used to do on my android projects..

    In Android Studio we can do similar operation by, Ctrl+Shift+F to find from whole project (Command+Shift+F in MacOs) and Ctrl+Shift+R to Replace ((Command+Shift+R in MacOs))

    0 讨论(0)
  • 2020-11-22 08:26

    I would consider using roboguice's logging facility instead of the built-in android.util.Log

    Their facility automatically disables debug and verbose logs for release builds. Plus, you get some nifty features for free (e.g. customizable logging behavior, additional data for every log and more)

    Using proguard could be quite a hassle and I wouldn't go through the trouble of configuring and making it work with your application unless you have a good reason for that (disabling logs isn't a good one)

    0 讨论(0)
  • 2020-11-22 08:26

    Add following to your proguard-rules.txt file

    -assumenosideeffects class android.util.Log {
      public static *** d(...);
      public static *** w(...);
      public static *** v(...);
      public static *** i(...);
    }
    
    0 讨论(0)
  • 2020-11-22 08:26

    You can try use this simple conventional method:

    Ctrl+Shift+R

    replace

    Log.e(
    

    With

    // Log.e(
    
    0 讨论(0)
  • 2020-11-22 08:26

    the simplest way;

    use DebugLog

    All logs are disabled by DebugLog when the app is released.

    https://github.com/MustafaFerhan/DebugLog

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