Abnormal behavior while using proguard

人走茶凉 提交于 2019-12-10 15:12:32

问题


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:


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.



来源:https://stackoverflow.com/questions/21024421/abnormal-behavior-while-using-proguard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!