I've a need to remove all logging from my release App type. I've tried configure proguard to do it for me. My configuration mostly match the one provided in here: proguard doesn't remove logs .
I've changed proguard-android.txt to proguard-android-optimize.txt but with no luck. After going through Proguard manual and checking output of :
-whyareyoukeeping 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(...);
public static int wtf(...);
}
learned that this couldn't be removed because of:
Explaining why classes and class members are being kept...
Printing usage to [...]...
android.util.Log
is a library class.
android.util.Log: boolean isLoggable(java.lang.String,int)
is a library method.
android.util.Log: int v(java.lang.String,java.lang.String)
is a library method.
android.util.Log: int v(java.lang.String,java.lang.String,java.lang.Throwable)
is a library method.
android.util.Log: int i(java.lang.String,java.lang.String)
is a library method.
android.util.Log: int i(java.lang.String,java.lang.String,java.lang.Throwable)
is a library method.
android.util.Log: int w(java.lang.String,java.lang.String)
is a library method.
android.util.Log: int w(java.lang.String,java.lang.String,java.lang.Throwable)
is a library method.
android.util.Log: int w(java.lang.String,java.lang.Throwable)
is a library method.
android.util.Log: int d(java.lang.String,java.lang.String)
is a library method.
android.util.Log: int d(java.lang.String,java.lang.String,java.lang.Throwable)
is a library method.
android.util.Log: int e(java.lang.String,java.lang.String)
is a library method.
android.util.Log: int e(java.lang.String,java.lang.String,java.lang.Throwable)
is a library method.
android.util.Log: int wtf(java.lang.String,java.lang.String)
is a library method.
android.util.Log: int wtf(java.lang.String,java.lang.Throwable)
is a library method.
android.util.Log: int wtf(java.lang.String,java.lang.String,java.lang.Throwable)
is a library method.
What could be reason for that? Maybe some other Proguard option? Is there any other option to enforce logs removal?
You need to specify that ProGuard should remove these logging calls using a configuration like that:
-assumenosideeffects class android.util.Log
{
public static int d(...);
public static int v(...);
public static int i(...);
public static int e(...);
}
Keep in mind that you need optimization to be enabled to actually remove these calls. For this use this default configuration:
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
With help of Guardsquare support I've been able to find out problem. One of libraries has -dontoptimize in its ProGuard config file. Helpful to narrow down this issue is option -printconfiguration [filename]
Doc. for ref - https://www.guardsquare.com/en/products/proguard/manual/usage#generaloptions
Related
I use this in each module of my multi-module library project
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '../proguard-rules-library.pro'
Is there any way I can disable configuration outputs to console on build stage? This is an example:
The proguard configuration file for the following section is C:\Users\pc\Development\project\build\app\intermediates\default_proguard_files\global\proguard-android.txt-7.2.2
This is a configuration file for ProGuard.
http://proguard.sourceforge.net/index.html#manual/usage.html
This is just a part of a log output. It goes on further with printing the contents of my proguard-rules-library.pro files
P.S. there is no -printconfiguration flag in the file, but default proguard-android-optimize has the -verbose flag. But I don't think it could be the cause of such behavior
You can remove logging calls with this option in proguard-project.txt:
-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 relevant if optimization is not disabled, like in proguard-android.txt. You have to specify proguard-android-optimize.txt instead, in project.properties:
proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt
I had a strange bug which was hard to find :-(
In my Android app I use Retrofit2 with Moshi do access an api. I also use proguard-android-optimize.txt to make my app clean and small. And in my proguard-rules.pro I have:
-assumenosideeffects class timber.log.Timber { *; }
-assumenosideeffects class android.util.Log { *; }
With this combination I get this error stream was reset: null when I try to access the api.
To fix it I have to remove this assumenosideeffects lines from my proguard config. But why? Has anyone an idea why I get this network problem when proguard removes logging methods?
The wildcard * matches all methods, including methods in super classes, like Object#wait(). You don't really want to remove those invocations, so you should explicitly list the methods for which you want to remove the invocations:
-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(...);
}
ProGuard already prints out a warning if you specify the wildcard.
Is it possible to exclude the implementation of Log class from the apk using ProGuard during the build generation? So when we generate an apk, we do not have the development Logs in the class files.
Yes, you can remove logs.
-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(...);
}
more information: Removing Log call using proguard
i am using Dexguard in my android application to protect from
reverse engineering.Now in my application which is very big ,i have
used several places System.out.println in many classes in which i am
printing my server URL to debugg for my ease.Now when i am releasing
this application ,and this apk i am giving to other developers ,they
can see all the System.out.println things in their logcat. how
should i avoid that. This has serious issue.
First of all you shouldn't be using System.out.println directly everywhere. Use your own wrapper class for logging.
In dexguard/proguard you can use assumenosideeffects for removing codes that are unnecessary for release.
So for System.out.print you can add following in your dexguard rules.
-assumenosideeffects class java.io.PrintStream {
public void println(%);
public void println(**);
}
But this is risky as this class might be used for purposes other than logging.
Fastest way for you would be to use android.util.Log in place of System.out.print and then add following
-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(...);
}
See proguard docs
good answer by #vKashyap, you might also want to add this as well...
-assumenosideeffects class java.lang.Exception {
public void printStackTrace();
}
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.