How do you debug a realm database that’s on a physical device?

This blog post is brought to you by the developer of BitBudget. BitBudget is an automated budgeting app for Android and iOS which syncs with your bank account and helps you avoid overspending. If you’d like to quit living paycheck-to-paycheck and get a better handle on your finances, download it today!

Alright, so let’s get to it: How to debug a realm database running on a physical device:

Unfortunately, you cannot debug a realm database running on a physical device if it is already in production.

Hopefully this saves someone out there a ton of heartache, but after you have pushed your app out in to production, you can’t just open up a .realm file from your device using Realm Studio due to security restrictions. So if you happen to find yourself struggling to open a realm database that’s running on your personal device, and can’t seem to access the .realm file to debug it, it could be that your device isn’t allowing access to the file because it is a production app and is not debuggable via USB and Android Studio, etc.

Now, if you need to debug a development version of your app, it’s a different story. You can simply open up your app in Android Studio, with your physical device plugged into your computer, and open up the Device File Explorer in Android Studio, where you will be able to locate your .realm database file. From the Device File Explorer you can right-click and save the .realm file onto your computer and open it using Realm Studio.

If you need to be able to debug and inspect Realm database instances running on live production versions of your app, this may be possible with Realm’s new Realm Cloud product. However, I haven’t checked out Realm Cloud and Realm Sync just yet as I’m still getting my feet wet with Realm DB.