Search code examples
javaandroidgoogle-chromeandroid-studiorealm

How to view Realm database using stetho realm for windows


I am having trouble using Stetho to view my Realm database in Chrome. I looked at this stackoverflow answer and have gotten to the point of the image in the second link. In the spot where it says inspect, on my computer it has nothing. It just shows the name of the emulator with no inspect button. I was able to get the inspect button before, but it has not been working. If someone could help that would be appreciated greatly!

Remote Target

LOCALHOST

Android SDK built for x86 #EMULATOR-5554

How to view my Realm file in the Realm Browser?

https://i.sstatic.net/qWtv2.png

Edit

App Build.gradle

    apply plugin: 'com.android.application'
    apply plugin: 'realm-android'

android {
compileSdkVersion 25
buildToolsVersion "24.0.2"

defaultConfig {
    applicationId "com.example.android.chargerpoints"
    minSdkVersion 17
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

ext {
supportLibVersion = '25.0.0'
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.0'
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"

// Gradle dependency on Stetho
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.uphyca:stetho_realm:2.0.0'


}

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

Project build.gradle

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath "io.realm:realm-gradle-plugin:2.3.0"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files

}
}

allprojects {
repositories {
        jcenter()
    }
}

task clean(type: Delete) {
delete rootProject.buildDir
}

MyApplication.java

package com.example.android.chargerpoints;

import android.app.Application;

import com.facebook.stetho.Stetho;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;

import io.realm.Realm;
import io.realm.RealmConfiguration;

public class MyApplication extends Application{

@Override
public void onCreate() {
    super.onCreate();

    Realm.init(this);

    RealmConfiguration config = new RealmConfiguration.Builder()
            .name("Chargers.realm")
            .schemaVersion(1)
            .build();

    Realm.setDefaultConfiguration(config);

    // Use the config
    Realm realm = Realm.getInstance(config);

    Stetho.initialize(
            Stetho.newInitializerBuilder(this)
                    .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                    .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
                    .build());

    realm.close();
}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.chargerpoints">

<application
    android:name= "MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".CouponsActivity"
        android:label="@string/title_coupons"
        android:parentActivityName = ".MainActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity"/>
    </activity>

    <activity android:name=".MyDealsActivity"
        android:label="@string/title_my_deals"
        android:parentActivityName=".MainActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity"/>
    </activity>

    <activity android:name=".IndividualCouponActivity"
        android:label="@string/title_individual_coupon"
        android:parentActivityName=".MainActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity"/>
    </activity>

    <activity android:name=".HelpActivity"
        android:label="@string/title_help"
        android:parentActivityName=".MainActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity"/>
    </activity>

    <activity android:name=".RedeemedCouponActivity"
        android:label="@string/title_redeemed_coupon"
        android:parentActivityName=".MainActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity"/>
    </activity>

</application>


Solution

  • You seem to be conflating a couple of things: Stetho and the Realm Browser. The Realm Browser is an OSX utility used to view Realm databases. If you are using OSX, get the browser from the App Store and then use adb to pull the database from your device/emulator as described here.

    If you are not using OSX, you may be able to browse the db from the device/emulator itself, using this library.

    Finally, there is a Stetho plugin for Realm, here. You will have to add it to your application, along with the Stetho libraries, to use it. The documentation for both libraries is pretty good.