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“类/合并/垂直”'但它没有帮助。