If your application is making requests to a server, you might be using some type of log to check whether or not your requests are successful. Unfortunately, those logs don’t get removed when you build the final APK (Android application package file). Removing logs is important to keep the logcat output as clean as possible. Leaving log statements in could also expose you to unintentional disclosure of sensitive information. In this hack, I’ll show you how easy it is to remove logs for your market release. Developers have their own technique preferences for removing logs from the final release. Some prefer doing something like the following:
if(BuildConfig.DEBUG)LOG.d(TAG,"Thelogmsg");
From my point of view, the best way to remove logs is to use the ProGuard tool. If you’ve never used ProGuard.
If you haven’t noticed yet, when we build an Android application we’ll find a pro-guard.cfg file in our project root directory. Its presence there doesn’t mean it’s on by default; we need to enable it. Fortunately, it’s simple: we need to add the following line in the default.properties file located in our project root directory:
proguard.config=proguard.cfg
Now ProGuard is enabled, but it’ll only be used when exporting a signed APK. We need to add the necessary lines to the proguard.cfg to get rid of those logs. Append the following lines to proguard.cfg:
-assumenosideeffectsclassandroid.util.Log{publicstatic***d(...);}
What we’re telling ProGuard is this: remove every use of a d() method with any amount of parameters that returns something and belongs to the android.util.Logclass. This will match with Log’s d() method and every debug log will be removed.
The ProGuard tool offers another way of polishing a release. Make sure you read the ProGuard manual and create a correct configuration for your project because Pro-Guard might remove essential code, thinking it’s not necessary for the application to work. If this happens, be sure to check that you’re telling ProGuard to keep every-thing you need. Notice that ProGuard isn’t only used to remove log statements. As I’m testing, I usually create methods in my Activity to populate forms. These methods are also something I use ProGuard to remove.
Refference :-
http://proguard.sourceforge.net/