0

我想在 Windows 上使用 Stetho 在 Chrome 浏览器中查看我的 Realm 数据库。

当我没有设置加密密钥时,我没有问题将其可视化,但由于我设置了它,当我尝试可视化数据库时我的应用程序崩溃抛出我的 Chrome 浏览器。

这是我在应用程序的 onCreate 中的源代码:

// Initialize Realm. Should only be done once when the application starts.
Realm.init(this);
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
    .encryptionKey("myencryptionkey64bits into bytes[]")
    .deleteRealmIfMigrationNeeded()
    .build();
Realm.setDefaultConfiguration(realmConfiguration);

// Create my RealmInspectorModulesProvider
RealmInspectorModulesProvider realmInspectorModulesProvider = RealmInspectorModulesProvider.builder(this)
    .withEncryptionKey("encrypted.realm", "myencryptionkey64bits into bytes[]")
    .build();

// Initialize Stetho
Stetho.initialize(Stetho.newInitializerBuilder(this)
    .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
    .enableWebKitInspector(realmInspectorModulesProvider)
    .build());

例外:

E/REALM_JNI: jni: ThrowingException 5, Realm at path '/data/data/com.mypackage/files/default.realm' already opened with a different encryption key. in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92, .
E/REALM_JNI: Exception has been throw: Unrecoverable error. Realm at path '/data/data/com.mypackage/files/default.realm' already opened with a different encryption key. in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92
E/REALM_JNI: jni: ThrowingException 5, Realm at path '/data/data/com.mypackage/files/default.realm' already opened with different inMemory settings. in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92, .
E/REALM_JNI: Exception has been throw: Unrecoverable error. Realm at path '/data/data/com.mypackage/files/default.realm' already opened with different inMemory settings. in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92

E/AndroidRuntime: FATAL EXCEPTION: StethoWorker-main-19
Process: com.mypackage.debug, PID: 31197
io.realm.exceptions.RealmError: Unrecoverable error. Realm at path '/data/data/com.mypackage/files/default.realm' already opened with different inMemory settings. in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92
    at io.realm.internal.SharedRealm.nativeGetSharedRealm(Native Method)
    at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:205)
    at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:182)
    at com.uphyca.stetho_realm.RealmPeerManager.openSharedRealm(RealmPeerManager.java:149)
    at com.uphyca.stetho_realm.RealmPeerManager.openSharedRealm(RealmPeerManager.java:128)
    at com.uphyca.stetho_realm.RealmPeerManager.getDatabaseTableNames(RealmPeerManager.java:55)
    at com.uphyca.stetho_realm.Database.getDatabaseTableNames(Database.java:124)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.facebook.stetho.inspector.MethodDispatcher$MethodDispatchHelper.invoke(MethodDispatcher.java:96)
    at com.facebook.stetho.inspector.MethodDispatcher.dispatch(MethodDispatcher.java:67)
    at com.facebook.stetho.inspector.ChromeDevtoolsServer.handleRemoteRequest(ChromeDevtoolsServer.java:129)
    at com.facebook.stetho.inspector.ChromeDevtoolsServer.handleRemoteMessage(ChromeDevtoolsServer.java:111)
    at com.facebook.stetho.inspector.ChromeDevtoolsServer.onMessage(ChromeDevtoolsServer.java:87)
    at com.facebook.stetho.websocket.WebSocketSession$1.handleTextFrame(WebSocketSession.java:176)
    at com.facebook.stetho.websocket.WebSocketSession$1.onCompleteFrame(WebSocketSession.java:136)
    at com.facebook.stetho.websocket.ReadHandler.readLoop(ReadHandler.java:44)
    at com.facebook.stetho.websocket.WebSocketSession.handle(WebSocketSession.java:45)
    at com.facebook.stetho.websocket.WebSocketHandler.doUpgrade(WebSocketHandler.java:117)
    at com.facebook.stetho.websocket.WebSocketHandler.handleRequest(WebSocketHandler.java:83)
    at com.facebook.stetho.server.http.LightHttpServer.dispatchToHandler(LightHttpServer.java:84)
    at com.facebook.stetho.server.http.LightHttpServer.serve(LightHttpServer.java:61)
    at com.facebook.stetho.inspector.DevtoolsSocketHandler.onAccepted(DevtoolsSocketHandler.java:52)
    at com.facebook.stetho.server.ProtocolDetectingSocketHandler.onSecured(ProtocolDetectingSocketHandler.java:63)
    at com.facebook.stetho.server.SecureSocketHandler.onAccepted(SecureSocketHandler.java:33)
    at com.facebook.stetho.server.LazySocketHandler.onAccepted(LazySocketHandler.java:36)
    at com.facebook.stetho.server.LocalSocketServer$WorkerThread.run(LocalSocketServer.java:167)

我确认,我为 Realm 或 Stetho 提供了相同的加密密钥。我想我错过了对象 Stetho 的错误初始化?

谢谢你的帮助!

4

1 回答 1

0

日志说你试图打开default.realmnot encrypted.realm

您可以尝试.withEncryptionKey("default.realm", "myencryptionkey64bits into bytes[]")代替.withEncryptionKey("encrypted.realm", "myencryptionkey64bits into bytes[]")吗?

或者,.withDefaultEncryptionKey("myencryptionkey64bits into bytes[]")如果您对所有领域文件使用相同的密钥,则可以使用。

于 2017-01-04T08:17:25.023 回答