3

我在一个 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.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

在调试中运行应用程序时,我收到类似的错误,但它不会导致崩溃。

任何方向在这里都会很棒。谢谢。

4

2 回答 2

3

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

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

-keep class net.sqlcipher.database.** {
    *;
}
于 2018-08-20T05:39:31.290 回答
1

当你从一个构建移到debug另一个release构建时,你开始得到NoSuchFieldError或类似的“嘿,这些东西不见了!” 错误,首先转到您的 ProGuard 设置。如果-keep类或包解决了问题,您至少有一个权宜之计的解决方案。不过,您可能会添加一个TODO项目以提出更细粒度的解决方案。

于 2016-03-09T20:45:54.703 回答