Development of mobile applications on the platform Android inevitably confronts engineers with the need to manage local information storage. Whether caching user data, saving settings, or working offline, the database remains a critical component of the architecture. However, creating tables and writing to them is only half the battle. To debug and verify the correct operation of the application, it is vital for the developer to be able to inspect the contents of the storage in real time.

In the environment Android Studio there are several effective ways to access database files installed on the emulator or physical device. Previously, this process required root access or the use of the command line ADB, which created unnecessary complications. Modern versions of the integrated development environment offer built-in visualization tools, such as App Inspection, which make the process transparent and convenient.

In this article, we will analyze in detail all the available methods: from using a graphical interface to manually exporting files through the device explorer. You'll learn how to connect to a database SQLite, how to work with Room and even how to view data in Realm. Understanding these tools will allow you to quickly find logic errors and optimize storage queries.

Using the App Inspection tool to visualize data

Starting with version Android Studio Arctic Fox, Google has introduced a powerful tool called App Inspection. This is the most modern and recommended way to view databases, since it does not require root access on the device and works directly through the debug bridge. The tool automatically detects connected processes and displays the table structure in a convenient tree view.

To launch the inspector, you must run the application in debug mode on an emulator or a real smartphone. After the application starts, go to menu View โ†’ Tool Windows โ†’ App Inspection. In the window that opens, select your application from the drop-down list of processes. If you use the library Room, you will immediately see a tab Database Inspectorwhere all connected databases will be listed.

The interface allows you to perform SQL queries directly from the inspector window. You can filter data, sort columns, and even edit cell values โ€‹โ€‹in real time, which is incredibly useful for testing boundary conditions. Changes made through the inspector are instantly reflected in the running application if it does not aggressively cache data in RAM.

๐Ÿ’ก

Make sure that your project has the androidx.sqlite:sqlite-framework dependency enabled for the inspector to work correctly with custom SQLite implementations.

โš ๏ธ Attention: The App Inspection tool only works with debug builds. If you try to connect it to the release version of the application with the flag disabled android:debuggable, the connection will fail.

One โ€‹โ€‹of the key features is the ability to monitor changes in tables in live mode. When the application makes new entries, they appear in the inspector table automatically without having to reload the tab. This significantly speeds up the search for duplicates or incorrect records that arise during complex synchronization logic.

Accessing files via Device File Explorer

If for some reason the graphical inspector is not suitable for you or you need to get the database file itself for external analysis, Device File Explorercomes to the rescue. This tool provides access to the file system of a connected device, simulating the work of a regular file manager, but with security restrictions Android.

Navigation to the database is carried out along a strictly defined path. Local application databases are stored in a protected directory that can only be accessed by the application itself or through superuser rights. In the explorer window, the path looks like this: /data/data/your_package_name/databases/. Here you will find files with the extension .db or .sqlite.

Unfortunately, on physical devices without root access the folder /data/data/ will not be readable. In this case, the system will show an empty directory or deny entry. However, on emulators from Google these restrictions are often removed by default, which allows you to freely copy files to your computer. Just right-click on the file and select Save As.

๐Ÿ“Š Which method of viewing the database do you use more often?
App Inspection
Device File Explorer
ADB commands
Third-party utilities

After saving the file to local developer disk, it can be opened with any third-party database editor, for example DB Browser for SQLite or DBeaver. This gives access to more advanced analysis functions, building mind diagrams and executing complex migration scripts that may not be convenient within the IDE.

Working with the database via the ADB command line

For experienced developers who prefer a terminal, or for automation tasks, working through Android Debug Bridge (ADB)is ideal. This method is universal and allows you to script the data upload process, which is useful for continuous integration (CI/CD). Commands are entered in the window Terminal at the bottom of the Android Studio screen.

The first step is always to check the device connections. Enter the command adb devicesto make sure that your device or emulator appears in the list with status device. If the device is not found, check whether USB debugging is enabled in the developer options on your smartphone. Next, you need to enter the device shell using the command adb shell.

Once inside the shell, you can use standard Linux utilities for navigation. Go to the database directory with the command cd /data/data/com.example.app/databases. To view the list of files, use ls -l. To copy a database file from a device to a computer, use the command pull, which is executed from computer mode (not inside the shell).

adb pull /data/data/com.example.app/databases/mydb.db C:/Users/Admin/Desktop/mydb_backup.db

If you do not have root access, direct access to the file may be denied. In this case, you can use the trick of changing access rights via run-asif the application is being debugged. The command adb shell run-as com.example.app switches the execution context to the application user, after which commands cp or cat become available to extract content to a public folder, for example, in /sdcard/.

โ˜‘๏ธ Check before exporting via ADB

Done: 0 / 4

Specifics of working with Room and migrations

The library Room is the standard solution for working with SQLite in the modern Android ecosystem. It provides an abstraction layer, but the data is still physically stored in regular SQLite files. When viewing the Room database through the App Inspector, you will see the same tables that are described in your entities (@Entity), plus service tables of the library itself.

Particular attention should be paid to the migration tables. Room creates a table room_master_table, which stores the hash sum of the database schema. When the application starts, this amount is checked against the expected one. If you manually change the table structure through an external editor without updating the schema version in the code, the application may throw an error the next time you launch it and refuse to work.

Table type Purpose Can be edited
Custom (Entity) Storing application data Yes, with caution
room_master_table Scheme version control No, will cause a crash
sqlite_sequence Auto-increment counters Not recommended
android_metadata Locale and settings No

When debugging migrations, it is useful to use the flag fallbackToDestructiveMigration in the database builder. This will allow the application to recreate tables if the schemas do not match, which is convenient at the development stage, but is categorically unacceptable in production due to the loss of user data. The visual inspector helps to verify that new columns actually appeared after applying the migration.

โš ๏ธ Warning: Manually adding columns to the database without a corresponding object Migration in the code will lead to unstable operation of the application. Always keep database changes in sync with your migration code.

Browse Realm Databases and Alternative Storage

Although SQLite dominates the platform, many developers choose Realm or ObjectBox to work with object-oriented data. These databases store information in binary files, the format of which is different from standard SQLite. The standard Database Inspector in Android Studio may not recognize their structure correctly without additional plugins.

There is a separate tool for Realm - Realm Studio. This is a desktop application that allows you to open files .realmfound in a directory /data/data/package/files/. It provides a powerful query interface that is similar to SQL but uses Realm Query Language syntax. The database file must first be downloaded to your computer via Device File Explorer.

The latest versions of Android Studio now include support for viewing Realm via a plugin, but the functionality may be limited compared to specialized software. If you are using encrypted Realm databases, to open the file in a third-party viewer you will need an encryption key, which is passed in the configuration during initialization.

What if the database file is 0 bytes?

If you see a database file that is 0 bytes, this usually means that the database has not yet been initialized or there was a write error. Try performing any write operation in the application and updating the list of files in the explorer.

Also worth mentioning DataStore is a modern replacement for SharedPreferences. Although it is not a relational database, data is stored in .pb (Protobuf) or .jsonfiles. You can view them as plain text if JSON mode is used, or through special protobuf viewers. They are located in the folder /data/data/package/files/datastore/.

Exporting and importing data for testing

One โ€‹โ€‹of the common tasks is the need to test an application on a large amount of data or on a specific set of records that is difficult to create manually. In such cases, the pre-population procedure is used. You can prepare a database on your computer, fill it with test data, and then place the file in the assets folder of your project.

When you first launch the application, it will copy this file from the assets to the internal memory of the device. For Room, this is configured through an annotation @Database with a parameter createFromFile or through a custom Callback. This ensures that all testers and users receive an identical set of initial data, making it easier to reproduce bugs.

The reverse process - exporting data from the user for analysis by technical support - is also implemented by copying the database file to external storage. By implementing the "Send logs and database" function, you can request a file from the user, open it in your DB Browser and instantly see the full picture of the application state at the time of the failure.

๐Ÿ’ก

Always check file access rights when copying the database to external storage, starting with Android 10 (API 29) the file access policy has become more stringent (Scoped Storage).

Why doesn't App Inspection see my application?

Make sure you run the application in Debugmode and not Release. Check if the library is connected androidx.sqlite. Also make sure that in the application manifest the attribute android:debuggable is set to true, which usually happens automatically for debug builds.

How to open the database if the device is not rooted?

Use the tool App Inspection, it does not require root access. If you just need a file, use the command adb shell run-as com.package.name to copy the file to a public folder /sdcard/, from where it can be taken without restrictions.

Is it possible to edit data in the database through Device File Explorer?

No, Device File Explorer is only intended for viewing and downloading files. To edit the content, use App Inspection inside Android