My Original code is :
private String hello;
private int i = 0;
public void test() {
if (i == 0) {
hello = "asdas";
} else {
hello = "asasvfasfas";
}
}
After Obfuscating with proguard :
private String a;
private int c = 0;
public void a()
{
if (this.c == 0);
for (this.a = "asdas"; ; this.a = "asasvfasfas")
return;
}
In project properties :
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
My proguard-project.txt file is empty, so I guess it should be using the default config file : proguard-android.txt.
Why it is behaving like this? How can I prevent this kind of code optimization? Please help.
Because your code is only that fragment you entered, I assume, your code will be easily optimized into this:
private String hello;
public void test() {
hello = "asdas";
}
The Proguard just doesn't remove your original but unreachable source lines, just puts them into unreachable places. It is converting your code into equivalent but not-so human friendly format.
So, the generated code works as yours, it is just obfuscated. If you don't like it, don't use obfuscators.
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