Proguard with OrmLite on Android

2020-01-24 21:37发布

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.

8条回答
疯言疯语
2楼-- · 2020-01-24 22:13

A small addition to the configuration above - if you're trying to serialize / deserialize Joda's DateTime objects via ORMLite, you probably need this as well:

-keepclassmembers class **DateTime {
    <init>(long);
    long getMillis();
}

...since ORMLite's DateTimeType does everything via reflection.

查看更多
不美不萌又怎样
3楼-- · 2020-01-24 22:14

I've came up with such solution (maybe will work for somebody too).

Made such changes to proguard.cfg:

  • Added -dontobfuscate option

  • Appended ,!code/allocation/variable to -optimization option

APK file size using such configuration reduced from 580 kB to 250 kB.

Though, no obfuscation is performed.

查看更多
登录 后发表回答