我出于调试原因使用java.lang.reflect.Proxy来实现所有可能的接口......但是这似乎很难让它与proguard一起工作。有什么建议吗?
THX -Marco
public class DebugLogListenerFactory {
public static IAirplaneListenerAll createStreamHandle(ICAirplane plane) {
DebugLogListenerHandler handler = new DebugLogListenerHandler(plane);
IAirplaneListenerAll proxy = (IAirplaneListenerAll) Proxy
.newProxyInstance(IAirplaneListenerAll.class.getClassLoader(),
new Class[] { IAirplaneListenerAll.class }, handler);
plane.addListener(proxy);
return proxy;
}
private static class DebugLogListenerHandler implements InvocationHandler {
private final Level levDef = Level.FINE;
public DebugLogListenerHandler() {
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
System.out.println("invoked" + method);
String methodName = method.getName();
String msg = methodName + ": ";
if (args != null) {
boolean first = true;
for (Object o : args) {
if (first) {
first = false;
} else {
msg += " ,";
}
msg += o.toString();
}
}
CDebug.getLog().log(levDef, msg);
return null;
}
}
}
答案 0 :(得分:0)
最简单的解决方案可能是避免缩小/优化/混淆接口及其方法:
-keep interface some.package.IAirplaneListenerAll {
<methods>;
}
你可能允许收缩:
-keep,allowshrinking interface some.package.IAirplaneListenerAll {
<methods>;
}
如果InvocationHandler可以处理混淆的方法名称,您也可以允许混淆:
-keep,allowshrinking,allowobfuscation interface some.package.IAirplaneListenerAll {
<methods>;
}