Abnormal behavior while using proguard

2019-06-23 09:08发布

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.

1条回答
一夜七次
2楼-- · 2019-06-23 09:28

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.

查看更多
登录 后发表回答