3

我用 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 模式的休眠

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.**{*; }
4

1 回答 1

0

问题是proguard + java 反射,例如Class.forName("com.example.class").getInstance()。

也适用于非android java项目,见:Proguard and Reflection in Android

于 2014-02-10T20:59:11.373 回答