我想在Windows上使用Stetho将我的Realm数据库查看到Chrome浏览器中。
当我没有设置加密密钥时,我没有问题可视化,但是因为我设置了它,当我尝试可视化数据库时,我的应用程序崩溃了我的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的错误初始化?
谢谢你的帮助!
答案 0 :(得分:0)
日志显示您正在尝试打开default.realm
而不是encrypted.realm
。
您可以尝试.withEncryptionKey("default.realm", "myencryptionkey64bits into bytes[]")
代替.withEncryptionKey("encrypted.realm", "myencryptionkey64bits into bytes[]")
吗?
如果您对所有领域文件使用相同的密钥,则可以使用.withDefaultEncryptionKey("myencryptionkey64bits into bytes[]")
。