Problems with obfuscation OrmLite and proguard

When I use Proguard for a project with OrmLite. I get this error :

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. 

I tried all the recommendations from Proguard with OrmLite on Android and from other resources, but with no results

+4
source share
4 answers

Put this in both the proguard-project file and the proguard optimization file (if you are using 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* 

and for each model class:

 -keep class com.xyz.components.** -keepclassmembers class com.xyz.components.** { *; } 

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

+5
source

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

 -keepattributes Signature 

for proguard configuration.

+1
source

You can use the following proguard configuration to save all model classes 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>(); } 
0
source

Just a small addition to the latest version of OrmLite 5 .

You can add these lines to hide some new warnings:

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

Look for more details in this thread: " how can I write a proguard configuration for ormlite? "

0
source

All Articles