启用了proguard的Ormlite无法找到id字段

时间:2016-08-17 09:23:42

标签: java android ormlite android-proguard

我的项目启用proguard有问题: java.sql.SQLException:无法删除类adc,因为它没有定义id字段

在exepction中提到的adc类遵循:

@DatabaseTable(tableName = "zaplanowane_zlecenie")
public class ZaplanowaneZlecenie {
    @DatabaseField(generatedId = true)
    private UUID mZaplanowaneZlecenieId;
    @DatabaseField(columnName = "data")
    private DateTime mZaplanowanaData;
    @DatabaseField(dataType = DataType.SERIALIZABLE)
    private ZlecenieFiltrowane mZaplanowanyAdres;
    @DatabaseField
    @Nullable
    private Double mLatitude;
    @DatabaseField
    @Nullable
    private Double mLongitude;

问题出现的时刻:

mPlannedRepo.deleteForDate(mSelectedData);

代码很简单 - 删除mDao.queryForEq找到的集合 虽然我没有使用proguard,但这些方法效果很好。但是如果我启用了proguard,我就提到了异常,而我的代码也没有用。

我的proguard文件(带OrmLite的片段):

# ORMLite uses reflection
-keepattributes *DatabaseField*
-keepattributes *DatabaseTable*
-keepattributes *SerializedName*
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

# Keep the helper class and its constructor
-keep class * extends com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
-keepclassmembers class * extends com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper {
  public <init>(android.content.Context);
}

请帮忙!我不知道这里发生了什么。

1 个答案:

答案 0 :(得分:2)

而不是使用这些不正确的ProGuard规则(有关有效属性名称的列表,请参阅ProGuard manual):

-keepattributes *DatabaseField*
-keepattributes *DatabaseTable*
-keepattributes *SerializedName*

你需要保留所有使用ORMLite注释注释的字段/类:

-keep @com.j256.ormlite.table.DatabaseTable class * {
    @com.j256.ormlite.field.DatabaseField <fields>;
    @com.j256.ormlite.field.ForeignCollectionField <fields>;
    <init>();
}