androidsqlciphersqlcipher-android

SQLCipher causing crash on Android in Signed Release APK


I am using SQLCipher in an android project. All works well in testing, but whenever I built a signed release APK and installed it I am receiving the following error and crash whenever I call

SQLCipher.loadLibs(context);

Here is the crash

03-09 14:47:45.833 24895-24895/? E/Database: Can't find SQLiteDatabase.mNativeHandle
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143] No pending exception expected: java.lang.NoSuchFieldError: no "I" field "mNativeHandle" in class "Lnet/sqlcipher/database/SQLiteDatabase;" or its superclasses
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String) (Runtime.java:-2)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at java.lang.String java.lang.Runtime.doLoad(java.lang.String, java.lang.ClassLoader) (Runtime.java:428)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void java.lang.Runtime.loadLibrary(java.lang.String, java.lang.ClassLoader) (Runtime.java:369)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void java.lang.System.loadLibrary(java.lang.String) (System.java:988)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void net.sqlcipher.database.SQLiteDatabase.a(android.content.Context, java.io.File) ((null):-1)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void net.sqlcipher.database.SQLiteDatabase.a(android.content.Context) ((null):-1)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void com.myapp.BBISDK.ax.o() ((null):-1)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void com.myapp.BBISDK.ax.<init>(java.lang.Integer, com.myapp.BBISDK.d.a, android.app.Activity) ((null):-1)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at com.myapp.BBISDK.ax com.myapp.BBISDK.ax.a(java.lang.Integer, com.myapp.BBISDK.d.a, android.app.Activity) ((null):-1)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void com.myapp.myapp.LoginActivity.onCreate(android.os.Bundle) ((null):-1)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:5990)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1106)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2278)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2387)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void android.app.ActivityThread.access$800(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:151)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1303)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void android.os.Looper.loop() (Looper.java:135)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:5254)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[], boolean) (Method.java:-2)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:372)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:903)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143]   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:698)
03-09 14:47:45.834 24895-24895/? A/art: art/runtime/thread.cc:1143] 
03-09 14:47:45.965 24895-24895/? A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x203a79ac in tid 24895 (kit.myapp)
 03-09 14:47:45.965 24895-24895/? I/libc: Suppressing debuggerd output because prctl(PR_GET_DUMPABLE)==0

I receive a similar error when running the app live in debug but it does not cause a crash.

Any direction would be great here. Thanks.


Solution

  • When you move from debug to release builds, and you start getting NoSuchFieldError or similar sorts of "hey, this stuff is missing!" errors, turn first to your ProGuard settings. If -keep of the class or package clears up the problem, you have at least a stopgap solution. You might add a TODO item to come up with a more fine-grained solution, though.