0
我有定義應用程序行爲的配置類。如果沒有配置類擴展另一個,那麼未使用的類將被Proguard刪除,並且代碼將得到有效優化。但是如果一個擴展了另一個,那麼兩個配置都會保留,代碼不會被優化。如何通過Proguard合併基類
interface ConfInterface {
boolean method();
}
class ConfNever implements ConfInterface {
public boolean method() {
return false;
}
}
final class Conf extends ConfNever {
public boolean method() {
return true;
}
}
public class Main {
public static void main(String[] args) {
new Test(new Conf());
}
}
class Test {
Test(ConfInterface ci) {
if(ci.method()) {
System.out.println("Print");
} else {
System.out.println("PrintNever");
}
}
}
Proguard的配置:
-injars bin/
-outjars out/
-libraryjars <java.home>/lib/rt.jar
-repackageclasses ''
-allowaccessmodification
-keep public class Main {
public static void main(java.lang.String[]);
}
-optimizationpasses 50
編譯,模糊和反編譯Test類:
final class c {
c(final a a) {
super();
if (a.a()) {
System.out.println("Print");
return;
}
System.out.println("PrintNever");
}
}
如果CONF類不延伸ConfNever然後ConfNever由Proguard的除去和Test類是(注:我禁用'優化通過50'保持測試類):
final class b {
b(final a a) {
super();
System.out.println("Print");
}
}
有沒有辦法讓Proguard合併Conf和ConfNever或檢測Test類是否只用Conf對象初始化並相應地優化?
更新:我試過'-optimizations「類/合併/垂直」'但它沒有幫助。