Problems with OrmLite and proguard obfuscation

2019-03-16 18:30发布

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.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've tried all recomendation from Proguard with OrmLite on Android and from others resources but without results

4条回答
迷人小祖宗
2楼-- · 2019-03-16 18:44

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?"

查看更多
我命由我不由天
3楼-- · 2019-03-16 18:46

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 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 every model class:

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

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

查看更多
可以哭但决不认输i
4楼-- · 2019-03-16 19:05

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.

查看更多
可以哭但决不认输i
5楼-- · 2019-03-16 19:05

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>();
}
查看更多
登录 后发表回答