129

Is there any easier way to see the contents of database created with Room Persistence Library in Android Studio?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
SpiralDev
  • 7,011
  • 5
  • 28
  • 42
  • 8
    `easier way` compared to which way? – Vladyslav Matviienko Jun 08 '17 at 07:35
  • 1
    compared to old approaches like using DDMS or via adb shell. DDMS freezes my computer and using adb requires a lot of work. I think there must be easier way as it was released by Google recently – SpiralDev Jun 08 '17 at 07:39
  • 12
    Not in android studio, but this https://github.com/facebook/stetho is the best Android Debug bridge developed by facebook, from which you can see your app database, even sharedpreferences, etc. – Moinkhan Jun 08 '17 at 08:45

20 Answers20

104

In older Android Studio versions:

Emulator -> Android Studio -> Device File Explorer -> /data/data/{$packageId}/databases/ -> Save As -> https://sqlitebrowser.org/

In later Android Studio versions (3.5+):

View -> Tool Windows -> Device File Explorer -> /data/data/{$packageId}/databases/ -> Save As -> https://sqlitebrowser.org/
Jeehut
  • 20,202
  • 8
  • 59
  • 80
k4dima
  • 6,070
  • 5
  • 41
  • 39
  • 2
    operation not permitted – Jono Jan 11 '19 at 13:22
  • 2
    @jonney This method will only work on rooted device or emulator. – Hitesh Bisht Mar 13 '19 at 10:32
  • 2
    This should also work on a non-rooted phone with debuggable app installed, except Samsung devices – Gaket Jun 10 '19 at 16:56
  • 1
    This should be the accepted answer - easiest way to get the DB without having to download software or root the device. – beyondtheteal Oct 08 '19 at 16:09
  • What do you mean by "Emulator"? On context menu of Android Studio I don't have it. – Jakub Jabłoński Nov 21 '19 at 08:52
  • 1
    @JakubJabłoński launch your app on emulator, than open Device File Explorer in Android Studio – k4dima Nov 21 '19 at 14:54
  • 1
    I should add this also: You have to save also "-shm" and "-wal" with original file so that you can open it with Sqlite DB browser. – Mahdi Feb 12 '20 at 01:27
  • Why sqlitebrowser.org versus a similar application? – Bink May 22 '20 at 20:40
  • 1
    is @chandan-sharma answered this answer need an update : With the latest release of the Android Studio 4.1 Canary, Android Studio provide new tool called Database Inspector. You can use this Database Inspector tool to view the database file and it's content, you can also edit database content. – golkarm Mar 10 '21 at 08:43
89

Database Inspector Officially Support in Android Studio

Previouslly, Database Inspector start to include in Android Studio 4.1 canary channel, now it is already build in with the latest version of Android Studio Arctic Fox.

Now, Database Inspector is under the App Inspection Tab. You have to choose your connected device, then need to choose package name that you want to inspect for database.

In the left side, show the available tables and need to double click to see table details, and it will be show in the right side.enter image description here.

Option 1

You can use Android-Debug-Database, and you can CRUD of your data from a browser, and then you can see your Preference data from a browser.

Option 2

If you don't want to use from Browser and you have to check other files,need to check your data changes, use a Genymotion Emulator.So you have to root your emulator.Try to Root your emulator, plz see in https://stackoverflow.com/a/44039429/2772552. Let me know if you are not OK.

Htoo Aung Hlaing
  • 2,173
  • 15
  • 26
  • Able to see database file but unable to view created tables in database. I have tried both methods – Ravikiran May 15 '18 at 01:02
  • 9
    Finally I found the solution after a day work. Export "userdatabase","userdatabase-shm" and "userdatabase-wal" files from emulator and open "userdatabase" file in sqlite viewer – Ravikiran May 15 '18 at 01:52
  • if .db is in the internal dir, you are not allowed to see there, manually copy .db file to external storage dir and it will work for u – Htoo Aung Hlaing May 16 '18 at 13:01
  • I had a problem with method 1 where it was causing read/write problems with other async tasks. Caused the app to freeze. – Jeffrey Feb 20 '19 at 02:37
  • is @chandan-sharma answered this answer need an update : With the latest release of the Android Studio 4.1 Canary, Android Studio provide new tool called Database Inspector. You can use this Database Inspector tool to view the database file and it's content, you can also edit database content. – golkarm Mar 10 '21 at 08:41
  • Just a note that if you're plugging into a real device, it needs to be on Android 8 or better to support this. – LordParsley Nov 10 '21 at 09:00
85

in android studio 3.1.*

in tool window bar click on "Device File explorer" generally you can find this in bottom right corner of the screenn

open directory in data/data/your-application-package/databases

with new architecture 3 files is created in databases directory

your-database-name
your-database-name-shm
your-database-name-wal

you have to export all 3 in the same directory

then open first one file (that is with your-database-name only ) in any sqlite browser.

and now you can see all your data .......

your-database-name-shm
your-database-name-wal

these two extra files are needed to open db file if you will open database file only, than you will not found any table in that file

Avinash Jadaun
  • 1,892
  • 17
  • 16
  • How can I find out where the "/data/data/..." path is on my filesystem? – Awais Hussain Sep 14 '18 at 12:43
  • The author of this answer actually shows where ``Device File Explorer` lives, which saves some time for newbies; hence +1 – Ilonpilaaja Sep 29 '18 at 15:47
  • @AwaisHussain : use `context.getDatabasePath("your-db-name.db")` – gMale Nov 28 '18 at 08:14
  • Press shift twice to search everywhere and type in Device File Explorer if its been removed from the bottom right hand corner in your android studio. – COYG Apr 26 '19 at 15:25
  • It's important to copy ALL 3 files. Copying only the one with the database name, will result in not synced data, even if the used SQL manager OPEN IT CORRECTLY with tables and create its own shm and wal. – Jumpa Aug 06 '20 at 09:42
50

Download & Install DB Browser for SQLite

In Android Studio versions >= 3.0:

Open Device File Explorer via:

View > Tool Windows > Device File Explorer

In "Device File Explorer" Go to:

data > data > PACKAGE_NAME > databases

where PACKAGE_NAME is the name of your package (it is com.edgedevstudio.sample in the example below)

Device File Explorer

Right click on the database and select Save As. Save it anywhere you want on your PC.

Open, DB Browser for SQLite & click 'open Database' and open the database. enter image description here

In the case of the example above, you should locate "todolist" NOT "todolist-shm" nor "todolist-wal"

If you do not export the 3 database files (db_name, db_name-shm & db_name-wal, where db_name = name of the database) you will not be able to read the database.

Community
  • 1
  • 1
EdgeDev
  • 2,376
  • 2
  • 20
  • 37
20

Personally i use Android Debug Database

Android Debug Database is a powerful library for debugging databases and shared preferences in Android applications.

Quick start

Add this to your app's build.gradle

debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'

Just start the application, you will see in the logcat an entry like follows :

D/DebugDB: Open http://192.168.1.104:8080 in your browser

enter image description here


enter image description here


For more information have a look at the github repo

chebaby
  • 7,362
  • 50
  • 46
16

For easy way, follow these steps:

  1. Download SQLiteBrowser program: Download SQLite for all OS
  2. Click "Device Exploler" where is Right-Bottom corner on Android Studio.
  3. You will see a lot of files. Do not worry! Follow path: data/data/{your app package name}
  4. Right click on "databases" and Save As in your computer.
  5. Open SQLiteBrowser and click "Open Database" than choose file which has same name with your database name.
  6. You can see files and select which has same name with your database table name.
  7. Final step, you can see "Browse Data" option near of "Database Structure" option. When you select it, you can see your data of database.

You can see steps and just follow numbers on below image

You can see steps on image.

canerkaseler
  • 6,204
  • 45
  • 38
14

With the latest release of the Android Studio 4.1 Canary, Android Studio provide new tool called Database Inspector.

You can use this Database Inspector tool to view the database file and it's content, you can also edit database content.

enter image description here

If you are using Room Persistence then it also provide facility to run @Query with in the Android Studio. You can see the run button of the left side of the @Query annotation.

enter image description here

If you are using LiveData then it will live reflect database content changes,

enter image description here

Chandan Sharma
  • 2,803
  • 1
  • 17
  • 25
7

Use Stetho.

Add it to your Android project as a dependency.

Call Stetho.initializeWithDefaults(this) in your Application and view your database using the chrome inspect tool. Enter the following in your chrome URL bar: chrome://inspect.

Presto! You can see your Room database.

arekolek
  • 9,128
  • 3
  • 58
  • 79
Izak
  • 909
  • 9
  • 24
3

I did this by following steps:

1) Download the db browser from following link.

https://sqlitebrowser.org/

2)Go to Device File Explorer from IDE & copy three file generated like enter image description here and select all three files : your-db, your-db-shm, your-db-wal

press ctrl+shift+s and paste it to some folder. Done.

3) finally open the your-db with DbBrowser App.

100RaBH
  • 161
  • 3
3

In latest versions of Android Studio, you can use Database Inspector inside App Inspection Tool Window

enter image description here



Go To App Inspection. Then select the process. Database Inspector will now show the database contents.

enter image description here

All Іѕ Vаиітy
  • 24,861
  • 16
  • 87
  • 111
2

With Android Studio 4.1 Canary 6 and higher, you can inspect, query, and modify your app’s databases using the new Database Inspector. For example, you can debug your running app by modifying values in your database and testing those changes on the device.

https://developer.android.com/studio/preview/features#database-inspector

Jeffrey Liu
  • 1,063
  • 1
  • 9
  • 18
1
You can see your database table on the DB Browser for SQLite & room DB.

 In android studio 
1. Click on View -> Tool Windows -> Device File Explorer -> data
2. Select your project package name -> database -> select all file and save on desktop

Install **DB browser for SQLITE** 
1. sudo apt-get install sqlitebrowser //write on your terminal for install DB browser
2. install DB browser for sqlite
3. click on Open database and select file where you had saved your data
4. click on Brower Data and see your tables

This is all where i have see my android room database
HandyPawan
  • 1,018
  • 1
  • 11
  • 16
1

You can now view it in Database Inspector in Android Studio

Image below

Database Inspector Tab in Android Studio

Jayesh N
  • 11
  • 1
  • 1
1

Database Inspector
In the new Android Studio Arctic Fox
Click on the App inspection
Select Database Inspector from the tab
Right Click on the Database name
Click Export as a File
After Download you View the database in DB Browser for SQLite Application
*Note Database Inspector works only if the app deployed on API 26

1

In android atudio you'll find a tab in the bottom "App Inspector" There is a seperate tab for Database inspection. From there you can see all the databases in the device

Supun Ayeshmantha
  • 499
  • 1
  • 5
  • 9
0

I recently tried Sethto By Facebook.

Stetho is a sophisticated debug bridge for Android applications. When enabled, developers have access to the Chrome Developer Tools feature natively part of the Chrome desktop browser

You just need to include it's gradle dependency and call in MainApp. That's it. You get access to all the tools in chrome window by using chrome://inspect/ including your sqlite database.

Following is a screenshot where inspected by Room Database on Emulator. I only tried in emulator so far.

enter image description here

Ajji
  • 3,068
  • 2
  • 30
  • 31
0

after getting your DB (3 files) from Device File Explorar as comments said above

I really recommend easy program like using "DB Browser for SQLite" https://sqlitebrowser.org/

Amr263
  • 143
  • 2
  • 8
0

Google official: Nowadays there's a super simple way to view your Room DB straight from Android Studio. So simple you will laugh =) Check this out: https://developer.android.com/studio/inspect/database

Barakuda
  • 790
  • 8
  • 16
0

Best and easy to view, edit, add & delete your roomdatabase in debug mode in android studio.

Implement dependency in build.gradle

debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'

Copy paste below code in your activity

public static void showDebugDBAddressLog() {
    if (BuildConfig.DEBUG) {
        try {
            Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
            Method getAddressLog = debugDB.getMethod("getAddressLog");
            Object value = getAddressLog.invoke(null);
            Log.d("link", "showDebugDBAddressLogToast: "+(String) value);
        } catch (Exception ignore) {

        }
    }
}

Call Activity in oncreate.

showDebugDBAddressLog();

Add permission in AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

Run The app in dubug mode

Search in logcat

link

You see the link in logcat

showDebugDBAddressLog: Open http://192.168.1.100:8080 in your browser

Open link "http://192.168.1.100:8080" in your browser.

Boom you see your all database. Thank You

Kumar Santanu
  • 603
  • 1
  • 7
  • 14
0

Follow the below documentation from Android

https://developer.android.com/studio/inspect/database

arango_86
  • 4,236
  • 4
  • 40
  • 46