2011-04-26 204 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>; 
}