Android開發中正確刪除Log的姿勢(proguard.config=proguard.cfg)

方法一:自定義LogUtils工具類,定義Log打印開關,如:

if(Buildconfig.DEBUG)
{
Log.d(TAG,"The Log is Printed.);
}

方法二:

最好的方法是,使用Android系統的the ProGuard tool.

什麼是he ProGuard tool?Android 的Documentation這樣寫的:



在Android工程的根目錄下,需要在project.properties先配置一下,Android開發環境默認是沒有開啓這個功能的:

打開project.properties,寫下:

proguard.config=proguard.cfg

這樣ProGuard tool就開啓了。


然後,在proguard.cfg文件中,增加下面的配置信息:

-assumenosideeffects class android.util.Log {
    public static *** d(...);
}

這段配置信息的意思是,移除所有的d( )方法,也就是debug log日誌的打印全部會移除。

這樣,打包文件的時候所有的Debug信息都將會被移除。


ok ,that's right.


we got it!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章