2012-10-04 158 views
4

当我在OrmLite项目上使用Proguard时。我收到此错误OrmLite和proguard混淆问题

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.name/com.package.name.activities.StartActivity}: 
java.lang.IllegalStateException: Could not find OpenHelperClass because none of the generic parameters of class class com.package.name.activities.StartActivity extends OrmLiteSqliteOpenHelper. You should use getHelper(Context, Class) instead. 

我已经尝试了所有recomendation从Proguard with OrmLite on Android和其他资源,但没有结果

回答

5

将下面的内容放在proguard-project文件和proguard优化文件中(如果使用优化)。

# Your application may contain more items that need to be preserved; 
# typically classes that are dynamically created using Class.forName: 
# ormlite uses reflection 
-keep class com.j256.** { *; } 
-keep class com.j256.** 
-keepclassmembers class com.j256.** 
-keep enum com.j256.** 
-keepclassmembers enum com.j256.** 
-keep interface com.j256.** 
-keepclassmembers interface com.j256.** 

-keepclassmembers class * { 
    public <init>(android.content.Context); 
} 

-keepattributes *Annotation* 

和每一个模型类:

-keep class com.xyz.components.** 
-keepclassmembers class com.xyz.components.** { *; } 

我不喜欢最后一位,但我厌倦了试图找到一个更好的解决方案。

0

您可以使用下面的ProGuard配置,以保持由OrmLite

-keep @com.j256.ormlite.table.DatabaseTable class * { 
    @com.j256.ormlite.field.DatabaseField <fields>; 
    @com.j256.ormlite.field.ForeignCollectionField <fields>; 
    # Add the ormlite field annotations that your model uses here 
    <init>(); 
} 
0

只是一个小除了为OrmLite 5最新版本中使用的所有模型类。

您可能要添加这些行到隐瞒了一些新的警告:

-dontwarn com.j256.ormlite.android.** 
-dontwarn com.j256.ormlite.logger.** 
-dontwarn com.j256.ormlite.misc.** 

寻找更多的细节到该主题:“how can i write the config of proguard for ormlite?