8

我正在尝试使用 Realm 创建一个演示应用程序,以使用 Facebook 的stetho浏览default.realm。每次我尝试使用chrome://inspect > Resources > Web SQL > default.realm在谷歌浏览器上打开 default.realm 时都会收到此错误

这就是我所做的。

构建.gradle

repositories {
    maven {
        url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
    }
}

dependencies {
    ...
    compile 'com.uphyca:stetho_realm:2.0.0'
    compile 'com.facebook.stetho:stetho:1.4.1'
}

我的应用类

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this).build();
        Realm.setDefaultConfiguration(realmConfiguration);

        Stetho.initialize(
                Stetho.newInitializerBuilder(this)
                        .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                        .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
                        .build());
    }
}

应用程序因此错误而崩溃:

E/AndroidRuntime: FATAL EXCEPTION: StethoWorker-main-304
                  Process: example.com.demoapp, PID: 12830
                  java.lang.NoClassDefFoundError: Failed resolution of: Lio/realm/internal/SharedRealm$Durability;
                      at com.uphyca.stetho_realm.RealmPeerManager.openSharedRealm(RealmPeerManager.java:136)
                      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 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)
                   Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.internal.SharedRealm$Durability" on path: DexPathList[[dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-support-annotations-24.2.1_fe2fc8f98c9647365914a4e0809de4cf3bdd5d0f-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-realm-android-0.87.4_a528e85f9603c6e64968c150f61258a1621159d0-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-jsr305-2.0.1_54f738210fc8c811d7251e6035f61735e3c90b00-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-internal_impl-24.2.1_d63817604dbcd8615733073ed4cf6bd29db871e2-classes.dex", dex file "/data/data/example.com.demoapp/files/instant-run/dex/slice-internal_impl-24.2.1_d432bb06a79cf966d865aa5fa44c857409504f1f-classes.dex", dex file "/data/data/example.com.d
4

1 回答 1

10

您正在使用一个非常过时的 Realm 版本,Stetho-Realm 2.0.0 不支持该版本。

您应该使用Stetho-Realm 的 1.x 分支来打开您的 Realm。

repositories {
    maven {
        url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
    }
}

dependencies {
    compile 'com.facebook.stetho:stetho:1.3.1'
    compile 'com.uphyca:stetho_realm:0.9.0'
}
于 2016-11-29T13:12:48.193 回答