我用proguard4.4混淆了我的代码,代码里有个空循环语句.
大概类似
boolean a = false;
new Thread().start //修改a 的值
while(a);我反编译他混淆后的代码一看while(a);这句已经不见了
加上个括号也不行
boolean a = false;
new Thread().start //修改a 的值
while(a){
}
必须做些操作,这代码才会出来
boolean a = false;
new Thread().start //修改a 的值
while(a){
System.out.print("");
}

解决方案 »

  1.   

    你的代码中虽然有,但是编译的时候或许已经给你优化掉了吧?!
    你编译成.class再反编译这个class,看看是否还在
      

  2.   

    如果还在就是proguard4.4给你优化掉了
      

  3.   

    我在网上找到了一个说明Disappearing loops
    If your code contains empty busy-waiting loops, ProGuard’s optimization step may remove them. More specifically, this happens if a loop continuously checks the value of a non-volatile field that is changed in a different thread. The specifications of the Java Virtual Machine require that you always  fields that are accessed across different threads without further synchronization as volatile. If this is not possible for some reason, you’ll have to switch off optimization using the -dontoptimize option.http://docs.huihoo.com/proguard/manual/troubleshooting.html大致的意思是,如果你的代码里有忙等待循环,那么Proguard的优化步骤很可能会把它移除掉,特别是当你在循环里不断检查的字段没有用valatile关键字修饰时。
    不过我后来加上 valatile 关键字后,空循环还是照样被移除。而且我调用的方法已经加了synchronized,我的代码也没有必要为这个变量加上valatile ,最后只能非常不爽地在项目的混淆选项界面里的其他混淆设置中添上一行-dontoptimize