Many thanks to @gunar for help. I solved the problem, the reason is that I include support package in proguard-project.txt
as -libraryjars
not as -injars
. Therefore it's content wasn't packed into resulting apk and dalvik cannot initialize DbHelper at runtime which uses classes from support package
Keep class from shrinking
-
01-06-2022 - |
Question
In my android app I have a DbHelper
class which extends OrmLiteSqliteOpenHelper
which extends SQLiteOpenHelper
. Running ProGuard on project completes successfully, but later in run-time I'm getting an error: java.lang.NoClassDefFoundError: com.example.myapp.mypackage.DbHelper
I'm added -keep class com.example.myapp.mypackage.** { *; }
into proguard-project.txt
to exclude my DbHelper
from shrinking but this doesn't helps.
Also I've tried to add -dontshrink
flag, just for test, to disable shrinking step, but this doesn't helps too.
Any suggestions what I do wrong and what to try? Thanks
UPD: Full stacktrace
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.example.myapp.mypackage.DbHelper
at com.example.myapp.App.onCreate(App.java:78)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4391)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
UPD 2: For OrmLite I'm using this config
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
UPD 3:
I'm tryed to undex classes.dex
from proguarded apk with dex2jar
tool and my DbHelper exists exactly where it should be
UPD 4: Nope, this isn't test application, this is usual android app
UPD 5:
Yes, DbHelper
use some kind of stuff from support package and in proguarded apk classes from suppord package is missed. In proguard-project.txt
I have this config for support package and Action Bar Sherlock
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
How I can correctly configure ProGuard to preserve support package from shrinking?
Solution