Possible Duplicate:
Removing unused strings during ProGuard optimisation
I have an Android application with dozens of logging statements. I'd prefer they wouldn't appear in the release version, so I used Proguard with something like this in the proguard.cfg
file:
-assumenosideeffects class android.util.Log {
public static *** d(...);
}
But the problem is that there are a lot of Log.d("something is " + something)
, and although the Log.d()
statement is being removed from the bytecode, the strings are still there.
So, following this answer, I created a simple wrapper class, something along the lines of:
public class MyLogger {
public static void d(Object... msgs) {
StringBuilder log = new StringBuilder();
for(Object msg : msgs) {
log.append(msg.toString());
}
Log.d(TAG, log.toString());
}
}
Then I edited my proguard.cfg
:
-assumenosideeffects class my.package.MyLogger {
public static *** d(...);
}
But the strings are still found in the generated bytecode!
Other than this, I am using the standard proguard.cfg
provided by the Android SDK. Am I doing something wrong?
Edit: after examining the generated bytecode, I saw that the strings were there, but they were not being appended one to another, as I thought. They were being stored in an array. Why? To pass them as variable parameters to my method. It looks like ProGuard doesn't like that, so I modified my logger class like this:
public static void d(Object a) {
log(a);
}
public static void d(Object a, Object b) {
log(a, b);
}
(... I had to put like seven d() methods ...)
private static void log(Object... msgs) {
(same as before)
}
It's ugly, but now the strings are nowhere in the bytecode.
Is this some kind of bug/limitation of ProGuard? Or is it just me not understanding how it works?