user1667307
user1667307

Reputation: 2071

Removing Log call using proguard

I am trying to use proguard to strip all my logs: I have entered the following line in my proguard-project.txt:

-assumenosideeffects class android.util.Log { *; }

And my project.properties looks like this:

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

Inspite of this the logs continue to show in my application. What exactly am I doing wrong here?

Upvotes: 45

Views: 38359

Answers (3)

Eric Lafortune
Eric Lafortune

Reputation: 45668

You shouldn't specify the '*' wildcard, because that includes methods like 'Object#wait()'. Better explicitly list the methods:

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

This option is only relevant if optimization is not disabled, like in proguard-android.txt. You have to specify proguard-android-optimize.txt instead:

proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

or with the contemporary Android Gradle plugin

buildTypes {
    releaseSomeBuildType {
        ...
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'your-proguard-file.pro'
    }
}   

Resources

Upvotes: 100

Arshiya Khanum
Arshiya Khanum

Reputation: 471

It's pretty late and I came across the same problem. I am using Android studio 1.3 and this is what I did.

  1. Add the log methods that you want to strip in your release build in proguard-android-optimize.txt:

    -assumenosideeffects class android.util.Log {
        public static boolean isLoggable(java.lang.String, int);
        public static int d(...);
        public static int w(...);
        public static int v(...);
        public static int i(...);
    }
    
  2. In your build.gradle (Module: app) set proguard-android-optimize.txt as default proguard file instead of proguard-android.txt:

    buildTypes {
        release {
            minifyEnabled true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
        }
    }
    

This is because in proguard-android.txt optimization is turned off by default with flags

-dontoptimize
-dontpreverify 

This worked for me, hope it helps others.

Upvotes: 16

Frank
Frank

Reputation: 15641

You need to do it like this:

-assumenosideeffects class android.util.Log {
public static int d(...);
public static int v(...);
public static int i(...);
public static int w(...);
public static int e(...);
public static int wtf(...);
    }

and expand for all the log methods you are using.

Upvotes: 7

Related Questions