java.lang.IllegalAccessError: Class ref in pre-ver

2019-07-04 16:41发布

问题:

I have my stable app that's been working for months now, and after adding appcompat_v7 to support Material theme everything went to crap. I just changed my Activities to ActionBarActivity and the theme to Theme.AppCompat

Once every other run I get

java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

inside a random library or in arbitrary points of execution not related to views. It requires a clean build and uninstall to get it to work again.

java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
            at java.lang.reflect.Field.getAnnotation(Native Method)
            at java.lang.reflect.Field.getAnnotation(Field.java:212)
            at com.j256.ormlite.android.DatabaseTableConfigUtil.configFromField(DatabaseTableConfigUtil.java:243)
            at com.j256.ormlite.android.DatabaseTableConfigUtil.fromClass(DatabaseTableConfigUtil.java:50)
            at com.j256.ormlite.db.SqliteAndroidDatabaseType.extractDatabaseTableConfig(SqliteAndroidDatabaseType.java:76)
            at com.j256.ormlite.dao.DaoManager.createDao(DaoManager.java:67)
            at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.getDao(OrmLiteSqliteOpenHelper.java:279)

EDIT:

Behaviour is erratic at best. It may or may not build and run correctly. My best guess is that appcompat_v7 doesn't like our config with multi-dex or having Gradle to not pre-dex libraries.

回答1:

You should include all your annotation classes in main dex.

The symptom is different, but the solution is the same as for this question:
How do you calculate which classes to put in your main-dex-list file?
There's a script that can generate it for you. I wrote a blogpost that shows how to use it.

Update (10/31/2014):
Gradle plugin v0.14.0 now does it automatically. See my answer here.