mesibo
mesibo

Reputation: 4348

proguard bug? removing logs

My proguard configuration

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

and

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

It does removes most of the logs. However for some logs, it produces strange output as shown below. As you can notice, the Log.d has been replaced by some redundant code.

public void MyFunction(int param1, String param2) {
    Log.d(TAG, "MyFunction: " + param1 + " : " + param2);

    ...some code...
}

This is transformed to

public final void a(int paramInt, String paramString)
{
new StringBuilder("MyFunction: ").append(paramInt).append(" : ").append(paramString);

... some code ...
}

}

Any idea what's wrong and how to solve this?

Thanks

Upvotes: 1

Views: 135

Answers (1)

Mimmo Grottoli
Mimmo Grottoli

Reputation: 5773

It's not a bug. You're telling proguard to remove Log.d/w/v/i/e method calls, not the entire line. As far as I know this is the best you can get. By the way the line new StringBuilder("MyFunction: ")... is the result of reverse engineering the bytecode of your class, and it's fine.

I want to give an example of why proguard remove just the method call and not the entire line. Take a look at this snippet:

int sum = 0;
int a = 10;
int b = 10;
assert a > 0;
assert b > 0;
Log.d("TAG", "The value of a+b is " + (sum=a+b));
// the sum of two positive number is a positive number
assert sum > 0;

What happen if proguard remove the Log.d line?

Upvotes: 1

Related Questions