1

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

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

I don't think it's fine. I am asking it to remove the line, but not to replace with some redundant code. Indeed limitation.
You are removing the invocation of the method not parameters that you use inside that method. And you cannot remove them! May I suggest you to use Timber? It's a small logging library that maybe can have better results.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.