SQLCipher 在签名版本 APK 中导致 Android 崩溃

SQLCipher causing crash on Android in Signed Release APK

我在 android 项目中使用 SQLCipher。一切都在测试中运行良好,但每当我构建一个签名的发布 APK 并安装它时,每当我调用

时,我都会收到以下错误并崩溃
SQLCipher.loadLibs(context);

这是崩溃

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.access0(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

当应用处于调试状态时 运行 我收到类似的错误,但它不会导致崩溃。

这里任何方向都很好。谢谢

当您从 debug 转移到 release 构建时,您开始收到 NoSuchFieldError 或类似类型的 "hey, this stuff is missing!" 错误,请首先转向您的 ProGuard 设置。如果 class 或包的 -keep 解决了问题,那么您至少有一个权宜之计。不过,您可能会添加一个 TODO 项目来提出更细粒度的解决方案。

我在我的 proguard 文件中修复了它

-keep class net.sqlcipher.** {
    *;
}

-keep class net.sqlcipher.database.** {
    *;
}