Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard with OrmLite on Android

How should I use proguard with ormlite library on Android?

Trying this:

-keep class com.j256.**
-keepclassmembers class com.j256.**
-keep enum com.j256.**
-keepclassmembers enum com.j256.**
-keep interface com.j256.**
-keepclassmembers interface com.j256.**

But I get:

03-23 20:23:54.518: E/AndroidRuntime(3032): java.lang.RuntimeException: Unable to start activity ComponentInfo{cz.eman.android.cepro/cz.eman.android.cepro.activity.StationsOverviewActivity}: java.lang.IllegalStateException: Could not find constructor that takes a Context argument for helper class class kb

I also tried to add this:

-keepclassmembers class * { public <init>(android.content.​Context); }

But I get another classmembers errors.

like image 617
sealskej Avatar asked Mar 24 '12 15:03

sealskej


3 Answers

Thank you a lot for posts like this that help us to advance step by step.

I've came up with other solution after i have tried the last one without success:

# 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.** { *; }

I hope it can help someone.

like image 59
German Avatar answered Oct 12 '22 10:10

German


The accepted answer was not enough for my case, so I enhanced it and this is what I ended up with:

# 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 annotations
-keepattributes *Annotation*

# 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>();
}
like image 30
Sebastian Avatar answered Oct 12 '22 10:10

Sebastian


I don't have the solution but here are a couple of references to help:

  • Proguard support request around ORMLite
  • ORMLite proguard discussion #1
  • ORMLite proguard discussion #2

You may be missing:

-keepclassmembers class * { 
  public <init>(android.content.Context); 
} 

and/or

-keepattributes *Annotation*
like image 15
Gray Avatar answered Oct 12 '22 12:10

Gray