我正在使用Realm。我安装了Stetho-Realm来查看领域数据。
这就是我所做的。
buildscript {
...
repositories {
google()
jcenter()
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
...
classpath "io.realm:realm-gradle-plugin:5.1.0"
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
}
maven {
url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
}
}
应用gradle
这是gradle代码。
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 27
defaultConfig {
...
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
...
}
dependencies {
...
// Stetho
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.uphyca:stetho_realm:2.1.0'
}
我的应用类别
public class MyApp extends Application{
@Override
public void onCreate() {
super.onCreate();
Realm.init(this);
RealmConfiguration config = new RealmConfiguration.Builder().build();
Realm.setDefaultConfiguration(config);
// Stetho
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
.build());
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
但是应用程序因以下错误而崩溃 : 在android studio上运行后,App已正常安装。应用程序出现在设备上后,我单击了“ chrome:// inspect /#devices:”中的“检查”。此时,该应用程序已崩溃并显示错误。如何通过Stetho查看领域db?
E/AndroidRuntime: FATAL EXCEPTION: StethoWorker-main-13
...
java.lang.NoClassDefFoundError: Failed resolution of: Lio/realm/internal/LinkView;
at java.lang.reflect.Executable.getParameterTypesInternal(Native Method)
at java.lang.reflect.Method.getParameterTypes(Method.java:179)
at java.lang.Class.getDeclaredMethods(Class.java:1881)
at com.facebook.stetho.inspector.MethodDispatcher.buildDispatchTable(MethodDispatcher.java:115)
at com.facebook.stetho.inspector.MethodDispatcher.findMethodDispatcher(MethodDispatcher.java:53)
at com.facebook.stetho.inspector.MethodDispatcher.dispatch(MethodDispatcher.java:60)
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.LinkView" on path: DexPathList[[zip file "/data/app/io.MyApp.app-xknjnMn3NM61rqAc4Zy3uA==/base.apk"],nativeLibraryDirectories=[/data/app/io.MyApp.app-xknjnMn3NM61rqAc4Zy3uA==/lib/arm64, /data/app/io.MyApp.app-xknjnMn3NM61rqAc4Zy3uA==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
答案 0 :(得分:7)
Stetho-Realm无需维护,不支持3.7.1以上的Realm版本
但是有一个社区分支:https://github.com/wickedev/stetho-realm
repositories {
maven { url 'https://github.com/WickeDev/stetho-realm/raw/master/maven-repo' }
}
dependencies {
implementation 'com.uphyca:stetho_realm:2.3.0'
}
val realmInspector = RealmInspectorModulesProvider.builder(this)
.withDeleteIfMigrationNeeded(true)
.build()
Stetho.initialize(Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(realmInspector)
.build())
答案 1 :(得分:0)
相对于Windows和Mac均可使用的Stetho,我更喜欢使用Realm Studio。您可以使用adb命令简单地提取领域db文件
adb拉 / [本地存储路径] / android / data // files / [领域文件] [您PC上文件夹的路径]