Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abnormal behavior while using proguard

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.

like image 694
Eldhose M Babu Avatar asked Nov 02 '22 07:11

Eldhose M Babu


1 Answers

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.

like image 114
Koshinae Avatar answered Nov 09 '22 02:11

Koshinae