2015-10-13 45 views
2

中的關於使用的方法,我從http://proguard.sourceforge.net/manual/usage.html讀到。我的問題是指以下段落:ProGuard

-assumenosideeffects class_specification 指定沒有任何副作用(比可能返回值等)的方法。在優化步驟中,ProGuard將 然後刪除對此類方法的調用,如果它可以確定返回 值未被使用。 ProGuard會自動分析您的程序代碼以找到 這樣的方法。它不會分析庫代碼,對於 這個選項因此可能有用。例如,您可以指定方法System.currentTimeMillis(),以便任何空閒調用 將被刪除。謹慎一些,你也可以使用 這個選項刪除日誌代碼。請注意,ProGuard將該選項應用於指定方法的整個層次結構 。僅適用於 優化。一般來說,做出假設可能是危險的;你可以用 輕鬆破解已處理的代碼。只有使用這個選項,如果你知道你在做什麼 !

我需要了解ProGuard如何確定「返回值未使用」。特別是,如果方法調用不返回任何值,它們是否總是被刪除?

回答

1

如果方法調用不返回任何值,它們是否總是被刪除?

答案是肯定的。一個例子是鉻sources:從發行版本

@RemovableInRelease註釋
private ChromeBrowserInitializer(Context context) { 
    mApplication = (ChromeApplication) context.getApplicationContext(); 
    mHandler = new Handler(Looper.getMainLooper()); 
    initLeakCanary(); 
} 

@RemovableInRelease 
private void initLeakCanary() { 
    // Watch that Activity objects are not retained after their onDestroy() has been called. 
    // This is a no-op in release builds. 
    LeakCanary.install(mApplication); 
} 

方法將被刪除。 chromium_code.flags

# Remove methods annotated with this if their return value is unused. 
-assumenosideeffects class ** { 
@org.chromium.base.annotations.RemovableInRelease <methods>; 
}