2011-04-26 167 views
0

我用于调试的原因java.lang.reflect.Proxy的东西有一个通用的方式来实现所有可能的接口......但这似乎很难得到它与proguard一起工作。有什么建议么?混淆与proguard与java.lang.reflect.Proxy

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

最简单的解决办法可能是为了避免收缩/优化/混淆的接口及其方法:

-keep interface some.package.IAirplaneListenerAll { 
    <methods>; 
} 

您可能允许萎缩:

-keep,allowshrinking interface some.package.IAirplaneListenerAll { 
    <methods>; 
} 

如果InvocationHandler可以处理混淆的方法名称,那么也可能允许混淆:

-keep,allowshrinking,allowobfuscation interface some.package.IAirplaneListenerAll { 
    <methods>; 
}