2014-01-09 57 views
5

我原來的代碼是:行爲異常,同時使用ProGuard

private String hello; 
private int i = 0; 

public void test() { 
    if (i == 0) { 
     hello = "asdas"; 
    } else { 
     hello = "asasvfasfas"; 
    } 
} 

使用ProGuard模糊處理後:

private String a; 
private int c = 0; 

public void a() 
    { 
    if (this.c == 0); 
    for (this.a = "asdas"; ; this.a = "asasvfasfas") 
     return; 
    } 

在項目屬性:

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 

我proguard的-project.txt文件是空的,所以我想它應該使用默認的配置文件:proguard-android.txt。

爲什麼它的行爲如此呢?我怎樣才能防止這種代碼優化?請幫忙。

+0

那些'this.a'或'this.c'? –

+0

@RohitJain:它的this.a本身...請找到更新的代碼。 –

+1

@EldhoseMBabu也許我在這裏錯過了一些東西,但是它不是在做它應該做的事情嗎? – Navin

回答

2

因爲你的代碼是隻有你輸入的片段,我想,你的代碼將被容易地優化成這樣:

private String hello; 

public void test() { 
     hello = "asdas"; 
} 

ProGuard的只是不刪除您原來的,但無法訪問源代碼行,把它們裝進進入無法到達的地方。它將您的代碼轉換爲等效但不是人性化的格式。

因此,生成的代碼與您的代碼一樣,只是被混淆了。如果你不喜歡它,不要使用混淆器。