在Android上使用OrmLite的Proguard

sea*_*kej 23 obfuscation optimization android proguard ormlite

我应该如何在Android上使用带有ormlite库的proguard?

试试这个:

-keep class com.j256.**
-keepclassmembers class com.j256.**
-keep enum com.j256.**
-keepclassmembers enum com.j256.**
-keep interface com.j256.**
-keepclassmembers interface com.j256.**
Run Code Online (Sandbox Code Playgroud)

但我得到:

03-23 20:23:54.518:E/AndroidRuntime(3032):java.lang.RuntimeException:无法启动活动ComponentInfo {cz.eman.android.cepro/cz.eman.android.cepro.activity.StationsOverviewActivity}:java .lang.IllegalStateException:找不到辅助类class kb的Context参数的构造函数

我也尝试添加这个:

-keepclassmembers class * { public <init>(android.content.?Context); }
Run Code Online (Sandbox Code Playgroud)

但我得到另一个班级成员错误.

小智 40

非常感谢你这样的帖子,帮助我们一步一步推进.

在我尝试了最后一个没有成功之后,我想出了其他解决方案:

# 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.** { *; }
Run Code Online (Sandbox Code Playgroud)

我希望它可以帮助别人.


Seb*_*ian 17

接受的答案对我的情况来说还不够,所以我加强了它,这就是我最终的结果:

# 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>();
}
Run Code Online (Sandbox Code Playgroud)

  • 对于ORMLite 5.0,我不得不添加`-dontwarn com.j256.ormlite.android.**``-dontwarn com.j256.ormlite.logger.**``-dontwarn com.j256.ormlite.misc.** (5认同)

Gra*_*ray 15

我没有解决方案,但这里有几个参考帮助:

你可能会失踪:

-keepclassmembers class * { 
  public <init>(android.content.Context); 
} 
Run Code Online (Sandbox Code Playgroud)

和/或

-keepattributes *Annotation*
Run Code Online (Sandbox Code Playgroud)