1. 程式人生 > >《jar,apk利用proguard去除日誌log不生效解決辦法》

《jar,apk利用proguard去除日誌log不生效解決辦法》

assumenosideeffects

    assumenosideeffects,proguard 配置檔案裡的引數。assume no side effects;假定無效;該屬性也就是標識無效程式碼。我們就是通過這個引數來讓proguard刪除日誌程式碼。

   assumenosideeffects的官方解釋:

           In the optimization step, ProGuard will then remove calls to such methods, if it can determine that the return values aren't used.ProGuard will analyze your program code to find such methods automatically.It will not analyze library code, for which this option can therefore be useful.

           In general, making assumptions can be dangerous; you can easily break the processed code. Only use this option if you know what you're doing!

    如下:

 -assumenosideeffects class android.util.Log {
           public static boolean isLoggable(java.lang.String, int);
           public static int v(...);
           public static int i(...);
           public static int w(...);
           public static int d(...);
           public static int e(...);
       }

   使用這個配置時,一定要注意-dontoptimize,配置。

    don‘t optimize 不要優化;將會關閉優化,導致日誌語句不會被優化掉。所以不能有這個配置