使用 Proguard 后无法让 Ormlite 工作
Unable to get Ormlite working after using Proguard
我正在使用 ormlite 4.24。
使用 shrinkResources true
构建发布版本后
minifyEnabled true
我的应用因以下错误而失败:
"java.lang.RuntimeException: java.sql.SQLException: SQL statement failed: CREATE TABLE `ac` (`A` VARCHAR , `B` VARCHAR , `C` VARCHAR..."
尝试以下选项后:
# OrmLite uses reflection
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
我仍然无法使用发布版本。
我试过使用 Ormlite 版本。 5 包括附加设置,例如:
# OrmLite uses reflection
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
# 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);
}
# keep the classes and members of our entities or OrmLite will not work
-keep class com.myApp.activity.**
-keepclassmembers class com.myApp.activity.** {*;}
# Keep the annotations
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-libraryjars <java.home>/lib/rt.jar
# Keep all model classes that are used by OrmLite
# Also keep their field names and the constructor
-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>();
}
-keepattributes Signature
-keep class com.myApp.activity.database.** { *; }
-keepclassmembers class classpath.** {
public *;
}
-dontwarn org.slf4j.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.apache.commons.codec.binary.**
-dontwarn javax.persistence.**
-dontwarn javax.lang.**
-dontwarn javax.annotation.**
-dontwarn javax.tools.**
但我仍然无法 运行 我的应用程序。我目前收到以下错误:
"java.lang.IllegalArgumentException: No fields have a DatabaseField annotation in class com.myApp.bean.p"
对于 OrmLite,我使用这个配置:
-keepattributes *Annotation*,Signature
-dontnote com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
-keepclassmembers class * extends com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper {
<init>(android.content.Context);
}
-dontnote com.j256.ormlite.field.DatabaseFieldConfig
-keepclassmembers class com.j256.ormlite.field.DatabaseFieldConfig {
<fields>;
}
-dontnote com.j256.ormlite.dao.Dao
-keepclassmembers class * implements com.j256.ormlite.dao.Dao {
<init>(**);
<init>(**, java.lang.Class);
}
-dontnote com.j256.ormlite.android.AndroidLog
-keep class com.j256.ormlite.android.AndroidLog {
<init>(java.lang.String);
}
-dontnote com.j256.ormlite.table.DatabaseTable
-keep @com.j256.ormlite.table.DatabaseTable class * {
void set*(***);
*** get*();
}
-dontnote com.j256.ormlite.field.DatabaseField
-keepclassmembers @interface com.j256.ormlite.field.DatabaseField {
<methods>;
}
-dontnote com.j256.ormlite.field.ForeignCollectionField
-keepclassmembers @interface com.j256.ormlite.field.ForeignCollectionField {
<methods>;
}
-keepclasseswithmembers class * {
@com.j256.ormlite.field.DatabaseField <fields>;
}
-keepclasseswithmembers class * {
@com.j256.ormlite.field.ForeignCollectionField <fields>;
}
-dontnote org.joda.time.DateTime
-keep,allowobfuscation class org.joda.time.DateTime
-keepclassmembers class org.joda.time.DateTime {
<init>(long);
long getMillis();
}
这应该是所有必要的。
我正在使用 ormlite 4.24。
使用 shrinkResources true
构建发布版本后
minifyEnabled true
我的应用因以下错误而失败:
"java.lang.RuntimeException: java.sql.SQLException: SQL statement failed: CREATE TABLE `ac` (`A` VARCHAR , `B` VARCHAR , `C` VARCHAR..."
尝试以下选项后:
# OrmLite uses reflection
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
我仍然无法使用发布版本。
我试过使用 Ormlite 版本。 5 包括附加设置,例如:
# OrmLite uses reflection
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
# 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);
}
# keep the classes and members of our entities or OrmLite will not work
-keep class com.myApp.activity.**
-keepclassmembers class com.myApp.activity.** {*;}
# Keep the annotations
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-libraryjars <java.home>/lib/rt.jar
# Keep all model classes that are used by OrmLite
# Also keep their field names and the constructor
-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>();
}
-keepattributes Signature
-keep class com.myApp.activity.database.** { *; }
-keepclassmembers class classpath.** {
public *;
}
-dontwarn org.slf4j.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.apache.commons.codec.binary.**
-dontwarn javax.persistence.**
-dontwarn javax.lang.**
-dontwarn javax.annotation.**
-dontwarn javax.tools.**
但我仍然无法 运行 我的应用程序。我目前收到以下错误:
"java.lang.IllegalArgumentException: No fields have a DatabaseField annotation in class com.myApp.bean.p"
对于 OrmLite,我使用这个配置:
-keepattributes *Annotation*,Signature
-dontnote com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
-keepclassmembers class * extends com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper {
<init>(android.content.Context);
}
-dontnote com.j256.ormlite.field.DatabaseFieldConfig
-keepclassmembers class com.j256.ormlite.field.DatabaseFieldConfig {
<fields>;
}
-dontnote com.j256.ormlite.dao.Dao
-keepclassmembers class * implements com.j256.ormlite.dao.Dao {
<init>(**);
<init>(**, java.lang.Class);
}
-dontnote com.j256.ormlite.android.AndroidLog
-keep class com.j256.ormlite.android.AndroidLog {
<init>(java.lang.String);
}
-dontnote com.j256.ormlite.table.DatabaseTable
-keep @com.j256.ormlite.table.DatabaseTable class * {
void set*(***);
*** get*();
}
-dontnote com.j256.ormlite.field.DatabaseField
-keepclassmembers @interface com.j256.ormlite.field.DatabaseField {
<methods>;
}
-dontnote com.j256.ormlite.field.ForeignCollectionField
-keepclassmembers @interface com.j256.ormlite.field.ForeignCollectionField {
<methods>;
}
-keepclasseswithmembers class * {
@com.j256.ormlite.field.DatabaseField <fields>;
}
-keepclasseswithmembers class * {
@com.j256.ormlite.field.ForeignCollectionField <fields>;
}
-dontnote org.joda.time.DateTime
-keep,allowobfuscation class org.joda.time.DateTime
-keepclassmembers class org.joda.time.DateTime {
<init>(long);
long getMillis();
}
这应该是所有必要的。