Michael B Michael B -3 years ago 132
Android Question

Debugging SQLite Database from Android App

I am writing an Android Application with a SQLite Database in the background.
This Database gets created by the App, and is stored on the default directory on the device:

shell@android: ls /data/data/com.package.example/databases #
MyDb.db
MyDb.db-journal


During development I want to test, if the rows are inserted / updated correctly, so I need to take a look on the database. There is a pretty nice tool called SQLite Database Browser (Available for Win, Mac and Linux).

With this tool I can open the database, browse, insert and update the rows and so on...
The problem is, that I first need to copy the database from the device to my local machine:

# On Android Shell
# (Cannot pull directly from /data/-directory)
cp /data/data/com.package.example/databases/MyDb.db /sdcard/


# On developing machine
adb pull /sdcard/MyDb.db


Than I have the database on my machine and I can finally open it.

My Question is: Is there a better / quicker way of doing it? Can I somehow directly access the database on the device?

Answer Source

There is an command-line version of sqlite3 available that allows you to directly access/view/modify an SQLite database in the adb (root) shell on the Android device without having to copy the database to your computer.

Of course you need root on the device, otherwise you can not access the app private directory with the database inside.

Edit: Some Android SQLite tools seem to implement something like an remote interface or a GUI for the command-line sqlite3 tool as described above. I have not tested it but SQLiteStudio in combination with it's DBAndroid plugin seem to provide GUI access from the PC to a database on the Android phone (without copying the database). Unfortunately the plugin is not free (commercial)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download