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?
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'
}
}
It's pretty late and I came across the same problem. I am using Android studio 1.3 and this is what I did.
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(...);
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With