当我在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.
我已经尝试了Proguard with OrmLite on Android和其他资源的所有推荐,但没有结果
答案 0 :(得分:5)
将以下内容放在proguard-project文件和proguard-optimization文件中(如果使用优化)。
# 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.** { *; }
我不喜欢最后一部分,但我已经厌倦了寻找更好的解决方案。
答案 1 :(得分:1)
答案 2 :(得分: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>();
}
答案 3 :(得分: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?”