Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 871
user1667307 Avatar asked Nov 04 '12 13:11

user1667307


3 Answers

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'
    }
}   
like image 79
Eric Lafortune Avatar answered Nov 01 '22 20:11

Eric Lafortune


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.

like image 39
arshiya Avatar answered Nov 01 '22 19:11

arshiya


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.

like image 7
Frank Avatar answered Nov 01 '22 19:11

Frank