Skip to content Skip to sidebar Skip to footer

Problems With Ormlite And Proguard Obfuscation

When I use Proguard on project with OrmLite. I recieve this error: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.name/com.package.name.activities.S

Solution 1:

Put the below in both your proguard-project file and your proguard-optimization file (if you use 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 classcom.j256.** { *; }
 -keep classcom.j256.**
 -keepclassmembers classcom.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*

and for every model class:

-keep classcom.xyz.components.**
-keepclassmembers classcom.xyz.components.** { *; } 

I don't like the last part one bit, but I'm tired of trying to find a better solution.

Solution 2:

I asked much the same question crash using ORMLite on Android with proguard and the answer was to add

-keepattributes Signature

to the proguard configuration.

Solution 3:

You can use the following proguard configuration to Keep all model classes that are used by 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>();
}

Solution 4:

Just a small addition for the latest version OrmLite 5.

You may want to add these rows to hide some new warnings:

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

Look for more details into this thread: "how can i write the config of proguard for ormlite?"

Post a Comment for "Problems With Ormlite And Proguard Obfuscation"