I\'m working on an Android application that stores data in a SQLite database. My question is, where does this database file get stored on the filesystem when you\'re using an emulator?
I have seen that it\'s stored in
/data/data/package_name/databases
but I need to know where on my local machine\'s hard drive that actually maps to. The database persists on multiple runs of the emulator, even after having shut down the machine, so it can\'t just reside in RAM...
The filesystem of the emulator doesn\'t map to a directory on your hard drive. The emulator\'s disk image is stored as an image file, which you can manage through either Eclipse (look for the G1-looking icon in the toolbar), or through the emulator binary itself (run \"emulator -help\" for a description of options).
You\'re best off using adb from the command line to jack into a running emulator. If you can get the specific directory and filename, you can do an \"adb pull\" to get the database file off of the emulator and onto your regular hard drive.
Edit: Removed suggestion that this works for unrooted devices too - it only works for emulators, and devices where you are operating adb as root.
An update mentioned in the comments below:
You don\'t need to be on the DDMS perspective anymore, just open the File Explorer from Eclipse Window > Show View > Other... It seems the app doesn\'t need to be running even, I can browse around in different apps file contents. I\'m
running ADB version 1.0.29
Or, you can try the old approach:
Open the DDMS perspective on your Eclipse IDE
(Window > Open Perspective > Other > DDMS)
and the most important:
YOUR APPLICATION MUST BE RUNNING SO YOU CAN SEE THE HIERARCHY OF FOLDERS AND FILES.
Then in the File Explorer Tab you will follow the path :
data > data > your-package-name > databases > your-database-file.
Then select the file, click on the disket icon in the right corner of the screen to download the .db file. If you want to upload a database file to the emulator you can click on the phone icon(beside disket icon) and choose the file to upload.
If you want to see the content of the .db file, I advise you to use SQLite Database Browser, which you can download here.
PS: If you want to see the database from a real device, you must root your phone.
The other answers are severely outdated. With Android Studio, this is the way to do it:
- Click on Tools > Android > Android Device Monitor
- Click on File Explorer
- Navigate to your db file and click on the Save button.
I wrote a simple bash script, which pulls database from android device to your computer (Linux, Mac users)
filename:android_db_move.sh
usage: android_db_move.sh com.example.app db_name.db
#!/bin/bash
REQUIRED_ARGS=2
ADB_PATH=/Users/Tadas/Library/sdk/platform-tools/adb
PULL_DIR=\"~/\"
if [ $# -ne $REQUIRED_ARGS ]
then
echo \"\"
echo \"Usage:\"
echo \"android_db_move.sh [package_name] [db_name]\"
echo \"eg. android_db_move.sh lt.appcamp.impuls impuls.db\"
echo \"\"
exit 1
fi;
echo\"\"
cmd1=\"$ADB_PATH -d shell \'run-as $1 cat /data/data/$1/databases/$2 > /sdcard/$2\' \"
cmd2=\"$ADB_PATH pull /sdcard/$2 $PULL_DIR\"
echo $cmd1
eval $cmd1
if [ $? -eq 0 ]
then
echo \".........OK\"
fi;
echo $cmd2
eval $cmd2
if [ $? -eq 0 ]
then
echo \".........OK\"
fi;
exit 0
Since the question is not restricted to Android Studio, So I am giving the path for Visual Studio 2015 (worked for Xamarin).
- Locate the database file mentioned in above image, and click on Pull button as it shown in image 2.
- Save the file in your desired location.
- You can open that file using SQLite Studio or DB Browser for SQLite.
Special Thanks to other answerers of this question.
The databases are stored as SQLite files in /data/data/PACKAGE/databases/DATABASEFILE where:
- PACKAGE is the package declared in the AndroidManifest.xml (tag \"manifest\", attribute \"package\")
- DATABASEFILE is the name passed when you call the SQLiteOpenHelper constructor as explained here: http://developer.android.com/guide/topics/data/data-storage.html#db
You can see (copy from/to filesystem) the database file in the emulator selecting DDMS perspective, in the File Explorer tab.
Simple Solution - works for both Emulator & Connected Devices
1 See the list of devices/emulators currently available.
$ adb devices
List of devices attached
G7NZCJ015313309 device emulator-5554 device
9885b6454e46383744 device
2 Run backup on your device/emulator
$ adb -s emulator-5554 backup -f ~/Desktop/data.ab -noapk com.your_app_package.app;
3 Extract data.ab
$ dd if=data.ab bs=1 skip=24 | openssl zlib -d | tar -xvf -;
You will find the database in /db
folder