On an Android Device where is located SQLite database, created by Room library

Viewed 2852

Where is located an app SQLite database created by Room library on a device?

Context: I have an app which create and use a Room database. To debug the database I would like to open it in a SQLite viewer app but I don't know where the database is located on a testing device.

6 Answers

Whether you use Room, OrmLite or SQLite in Android all are located within databases folder of application package.

You can access the databases folder by following below steps.

  • View > Tool Windows > Device File Explorer

enter image description here

From Device File Explorer go to data folder in which all the application packages are stored. Make sure that Emulator or device is connected.

  • data > data

enter image description here

Then, find you application package and go to your database.

  • com.company.my > databases > yourdatabasename.db

enter image description here

You can then save your database in your computer and do anything you want with it.

enter image description here

I use SQLiteBrowser to browse the database.

Go to Tools -> DDMS or click the Device File Explorer below Layout Preview in right bar.

Device Monitor window will open.

In File Explorer tab, click data -> data -> your project name -> databases.

Click pull a file from device icon. Save the file using .db extension.

I suggest please use Stetho library provided by the Facebook, so you don't need to pull the database every time. You can check the database in browser.

http://facebook.github.io/stetho/

You can also debug your database on desktop browser with the help of this awesome library Android-Debug-Database. Note that your mobile device on which you are running the app and desktop/laptop must be connected to same network.

you can use :

String path = getDatabasePath("you_database_name").getAbsolutePath();

Other than @musooff answer, if you want to save the database to local storage or want to give a custom path to your database. Then you can use the following approach:

val DATABASE_NAME = Environment.getExternalStorageDirectory().toString() + File.separator + "MyDBFolder" + File.separator + "example.db"

Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME).build()

This will create a folder MyDBFolder containing example.db database in your local storage. From there you can easily access the database.

  • Related to [SQLiteBrowser]

An update to @musooff using SQLiteBrowser to browse the database.

SQLiteBrowser no longer works for Room database Inspection.

You can now use the official Database Inspector for Android Studio.

Select View > Tool Windows > App Inspection from the menu bar.

Related