Tiny note about proguard unnecessary logging

Applying Proguard helps reducing the APK file size and making your app more secure with obfuscating and so on.

Today one of my coworkers was talking about unnecessary logging codes that are very familiar to most of Android developers, which look something like this:

Log.v("returning value is " + value);

which I know is already ugly; or if you are using Timber, you can write like this:

Timber.v("returning value is %s", value.toString());

In our project, we use Timber as well as Dagger, and thanks to the Dependency Injection, we’ve implemented to output log in any debug build, but for release build, we make it available only if LogLevel is ERROR and otherwise make it silent. I was thinking it was “enough” since although logging codes are still there, the codes inside of it will never be called on the production.

However, what my coworker found out today is that we can erase those unnecessary logging codes from release APK file using Proguard.

Apply Proguard to unnecessary logging

To put it straightforward, you can specify in your progurad setting file like this:

-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(...);

And make sure you write this setting on proguard-android-optimize.txt.

I haven’t actually tried it yet, but it’s on stackoverflow which you can find the link of it below.