ProGuard java和反射

时间:2012-06-26 09:01:23

标签: proguard obfuscation

我用proguard混淆了我的jar应用程序。当我运行程序时,我收到以下错误:

java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflec
t.ParameterizedType
    at gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateGenericDAO.
<init>(Unknown Source)
    at gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateDBSynchroni
zerDAO.<init>(Unknown Source)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at     gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateBridgeDAOFactory.instantiateDAO(Unknown Source)
    at gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateBridgeDAOFactory.getDBSynchronizerDAO(Unknown Source)
    at gr.analysis.synchronizer.forms.synchronizer.SynchronizersDialog.initSynchronizers(Unknown Source)
    at gr.analysis.synchronizer.forms.synchronizer.SynchronizersDialog.perform(Unknown Source)
    at gr.analysis.synchronizer.forms.synchronizer.SynchronizersDialog.access$1400(Unknown Source)
    at gr.analysis.synchronizer.forms.synchronizer.SynchronizersDialog$13$1.
run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
ERROR [Performer] (?:?) - java.lang.RuntimeException: Can not instantiate DAO: class     gr.analysis.synchronizer.bridge.dao.HibernateDAO.HibernateDBSynchronizerDAO

我使用带有注释和dao模式的hibernate

proguard的配置是:

-dontnote
-verbose
-printmapping out.map

-keepattributes *Annotation*
-keepdirectories

# The main entry points.

-keep public class gr.analysis.synchronizer.ApplicationSupport {
    public static void main(java.lang.String[]);
}


-keep class  gr.analysis.synchronizer.**{*; }

1 个答案:

答案 0 :(得分:0)

问题是程序+ java反射,例如的Class.forName( “com.example.class”)。的getInstance()。

也适用于非Android java项目,请参阅:Proguard and Reflection in Android