java.lang.NoClassDefFoundError: Failed resolution of: Lio/realm/internal/SharedRealm$Durability

java.lang.NoClassDefFoundError: Failed resolution of: Lio/realm/internal/SharedRealm$Durability

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

这就是我所做的。

build.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'
}

我的申请class

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.handleTextFrame(WebSocketSession.java:176)
                      at com.facebook.stetho.websocket.WebSocketSession.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

您使用的是极其过时的 Realm 版本,Stetho-Realm 2.0.0 不支持该版本。

您应该使用 the 1.x branch of Stetho-Realm 打开您的 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'
}