Debugging Android Databases And Shared Preferences In The Easiest Way

Debugging your application is an important part of the Android Development.

Make Debugging Great Again.

When it comes to debugging databases in an android application, it is very difficult to see what’s happening inside the database. The same is true with shared preferences.

For that, I have created a library to make it simple.

What can Android Debug Database do?

  • See all the databases.
  • See all the data in the shared preferences used in your application.
  • Run any sql query on the given database to update and delete your data.
  • Directly edit the database values.
  • Directly edit shared preferences.
  • Directly add a row in the database.
  • Directly add a key-value in the shared preferences.
  • Delete database rows and shared preferences.
  • Search in your data.
  • Sort data.
  • Export Database.
  • Check Database version.
  • Download database

All these features work without rooting your device -> No need of rooted device.

Using Android Debug Database Library in your application

Add this to your app’s build.gradle

debugCompile 'com.amitshekhar.android:debug-db:1.0.1'

That’s all, just start the application, you will see in the logcat an entry like follows :

D/DebugDB: Open http://XXX.XXX.X.XXX:8080 in your browser

You can also always get the debug address url from your code by calling the method DebugDB.getAddressLog().

Most importantly, when you use debugCompile, it will only compile in your debug build and not in your release apk.

Now open the provided link in your browser.

Important:

  • Your Android phone and laptop should be connected to the same Network (Wifi or LAN).
  • If you are using it over usb, run adb forward tcp:8080 tcp:8080

Working with emulator

  • Android Default Emulator: run adb forward tcp:8080 tcp:8080 and open http://localhost:8080
  • Genymotion Emulator: Enable bridge from configure virtual device (option available in genymotion)

Note : If you want use different port other than 8080. In the app build.gradle file under buildTypes do the following change :

debug {
    resValue("string", "PORT_NUMBER", "8081")
}

You will see something like this:

Seeing values

Editing values

Here, you can see the databases and shared preferences.

Do many many things like run sql query to update, delete the data, and much more.

Happy Debugging :)

Also, Let’s become friends on Twitter, Linkedin, Github, and Facebook.