之前在程序中有打了很多的log,当初打log的方式也没有统一,删掉肯定不行,统一修改也挺麻烦的。今天在stackoverflow上面看到有对这个的讨论
主要有以下三种方式关闭log信息http://stackoverflow.com/questions/2446248/deactivate-any-calls-to-log-before-publishing-are-there-tools-to-do-this
方法一:
- if(condition)
- Log.d(LOG_TAG, "Something");
缺点:每打log都要做判断
方法二:
I find a far easier solution is to forget all the if
checks all over the place and just use ProGuard to strip out any Log.d()
or Log.v()
method calls when we call our Ant release
target.
That way, we always have the debug info being output for regular builds and don't have to make any code changes for release builds. ProGuard can also do multiple passes over the bytecode to remove other undesired statements, empty blocks and can automatically inline short methods where appropriate.
For example, here's a very basic ProGuard config for Android: