See your Android Realm Database with Stetho

Ruwanka De Silva
Aug 27, 2017 · 2 min read

This is for folks who use Realm DB as the mobile application persistent solution. There are advantages of using Realm DB, some may argue that there are less. I am not going to vote (not now). I stucked, didn’t had a clue on what’s going on my android app database. Here how I looked inside of it.

I assume you have android app with Realm DB setup. If not follow along and create simple one.

Stetho is a cool tool by Facebook, it’s a debug bridge. Basically it provides android app inspection via google chrome dev tools. Setting up Stetho is straight forward. So let’s begin with basic configuration. We need to have few dependencies, Stetho, Realm and third party library that helps to use Stetho to inspect realm database. It’s called stetho-realm. Kudos to the contributors, this would be a nightmare if they didn’t develop this awesome library.

There are some important things to mention. Realm has to be added in project level build.gradle file. Also to use stetho-realm, maven repository has to be added to the project level build.gradle.

Next thing is to add Application class and setup Stetho and realm there. Also you need to add realm plugin in module build.gradle after android plugin and two dependencies for Stetho and stetho-realm.

Application class

Once app class is ready, add it in the manifest. Have some realm model classes and save them on start or provide functionality to save, so we can inspect it via chrome dev tools.

Save some data in realm database

Start application, add some data if it doesn’t add any on start. Go to chrome://inspect in your chrome browser.

Devices section shows Stetho enabled applications

Click on inspect link, now you can inspect realm db data in resources -> websql category.

Realm Db of the application

There are many other options that stetho-realm provides, even you can inspect your encrypted realm db using this method. You just need to add some configuration to the stetho-realm builder. Stetho it self is quite handy tool, with third party and official plugins you can get most out of your app. Try it out and have fun coding.

Inspired by: https://stackoverflow.com/questions/28478987/how-to-view-my-realm-file-in-the-realm-browser/34187414#34187414

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade