2016-08-11 33 views
1

我正在使用ormlite 4.24。使用Proguard後無法使Ormlite工作

建設使用一個發佈版本後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" 

回答

3

對於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(); 
} 

這應該是所有的必要。