Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

crash using ORMLite on Android with proguard

We're using ORMLite in our Android app. It's working fine, except when we try to do a build with proguard switched on.

I've read various similar posts, and so far I've got in my proguard-project.txt

-keep class com.j256.** {
   *;
}

as suggested in the following discussion http://sourceforge.net/p/proguard/discussion/182456/thread/6765bb69

and I've got

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

as suggested in another stackoverflow question Proguard with OrmLite on Android

But it still not working. I can get it to run if I add

-dontobfuscate

but that somewhat missing the point of using proguard in the first place.

When I run I get an

IllegalStateException: Could not find OpenHelperClass because none of the generic
parameters of class class <our.package.name>.LaunchActivity extends
OrmLiteSqliteOpenHelper.  You should use getHelper(Context, Class) instead.

Where

public class LaunchActivity extends OrmLiteBaseActivity<DatabaseHelper>

and

public class DatabaseHelper extends OrmLiteSqliteOpenHelper

I've added

-keep public class * extends com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper

-keep public class <our.package.name>.LaunchActivity

But still no luck. This question seems to have been asked before (Problems with OrmLite and proguard obfuscation) but I'm hoping somebody will know what the solution is!

like image 955
Jonathan Caryl Avatar asked Jan 10 '13 17:01

Jonathan Caryl


1 Answers

The error message mentions generic parameters, so ORMLite is probably using reflection to retrieve generic type information. This information is stored in optional Signature attributes (Java erases generic types), which ProGuard removes by default. You can keep them with

-keepattributes Signature
like image 85
Eric Lafortune Avatar answered Oct 07 '22 06:10

Eric Lafortune