I am using genymotion for my dev and when I create a database I can't see it in DDMS folder of genymotion emulator.
When searched on google I am able to see the database on adb shell but don't know how to pull the database to my local disk to view the data.
Can anyone please let me know the process.
Thanks in advance
Try on Genymotion 2.3:
adb shell su -c cp /data/data/<package.name>/databases/<database.name> /sdcard/
and on other version :
adb shell su 0 cp /data/data/<package.name>/databases/<database.name> /sdcard/
And pull it from the device
adb pull /sdcard/<database.name>
(edited, not the same comportment of su in 2.3 and 4.3)
You can (also) pull the data from your device to your host by copying it to a shared folder:
adb shell su 0 cp /data/data/<package.name>/databases/<database.name> /mnt/shared/
Here is how to setup the shared folder:
Go to your VirtualBox VM setting / Shared folder tab
Add a shared folder with the folder you want to shared, and check the "auto mount" option
Start your VM as usual from the Genymotion software
Your shared folder is available in the /mnt/shared directory (multiple shared folders are supported)
pull database using adb commands
adb pull /data/data/com.android.packagename/databases.datebase.db
the db will be pulled to current location where terminal is pointing to
then open db using sqliteman
Related
I'd like to insert data directly into the sqlite database of my app but I cannot find it anywhere on android studio path, even on my root path:
$sudo find / -type f -name 'myapp.db'
I know several similar questions have been asked before but the answers for Windows did not help me on Ubuntu Linux. So appreciate your help.
Android Studio does not store the database locally in your computer. The databases only exist in the devices & every time you deploy to a new device, your database will be created new in that new device. That is why you can't find it in your computer. Here is where the database is located in the device:
/data/data/full_qualified_java_package_name/databases/database_name.db
Now if you would like to insert data directly, you can use the terminal in Android Studio & use ADB to pull the database off the emulator, modify it, and push it back in. Heck I am sure that if you know enough Linux you could probably insert what you need into it without pulling it from the device. Here are some sample commands for the Android Studio terminal for that:
~/Android/Sdk/platform-tools/adb devices
Get the device number, then:
~/Android/Sdk/platform-tools/adb -s emulator-#### pull /data/data/full_qualified_java_package_name/databases/database_name.db <local-filepath>
And to send it back in, it is just:
~/Android/Sdk/platform-tools/adb -s emulator-#### push <local-filepath> /data/data/full_qualified_java_package_name/databases/database_name.db
Example:
~/Android/Sdk/platform-tools/adb -s emulator-5554 pull /data/data/com.danielkaparunakis.stackoverflowquestions/databases/Questiondatabase.db /Users/DanielKaparunakis/Desktop
Additional tip: If you leave the blank when you pull like this:
~/Android/Sdk/platform-tools/adb -s emulator-5554 pull /data/data/com.danielkaparunakis.stackoverflowquestions/databases/Questiondatabase.db
It will automatically pull it to your project's root folder.
It will save it in the internal storage of every device, if you don't have a rooted device it will not allow you to pull it, but, if you are using an emulator you will be able to pull it.
https://developer.android.com/training/basics/data-storage/databases.html
You app's db is only on the device. You can pull it from any connected device – non-rooted physical devices as well. This script pulls it from the first device.
This trick is run-as <package name> which runs a shell the app's directory with full access to the app's data.
Replace $package with your app's package name and replace $db with the name of you app's db.
$ LC_ALL=C adb exec-out run-as $package cat databases/$db >db.sqlite
LC_ALL=C is to avoid some strange locale behavior on some systems.
adb is by default installed by Android Studio to ~/Android/Sdk/platform-tools/adb.
Update
The program 'adb' is currently not installed. To run 'adb' please ask your administrator to install the package 'android-tools-adb'
This is Ubuntu telling you that you can install it from the Ubuntu package manager.
Normally you would already have it as a part of Android Studio.
Update 2
I don't have a script yet for pushing it back since push and run-as don't work together. You would have to do something like this (untested).
$ adb push db.sqlite /sdcard/temp.sqlite
$ cat <<EOF | adb shell
run-as $package
cat /sdcard/temp.sqlite >databases/$db
exit
exit
EOF
I am using a MacBook as my development machine. My Android phone is not rooted. I want to copy my Android app's file from phone to my MacBook. I tried the following:
Connect Android phone to MacBook (Developer's option is enabled)
adb pull /data/data/com.my.app/app_data/data ~/Documents/my/app/
where /data/data/com.my.app/app_data/data is the file path on phone, and ~/Documents/my/app/ is the directory path on MacBook.
But the above adb pull command shows Permission denied.
I also tried to use su under adb shell, but it doesn't work either:
~$ adb shell
shell#xyz:/ $ su
/system/bin/sh: su: not found
So, how can I copy my app's internal file to my MacBook directory?
On a non-rooted phone you can not access the app private data directory (/data/data/com.my.app).
The only way to extract the data is to create a backup of the app data using adb backupp:
adb backup -f mybackup.ab com.my.app
For extracting the information from the created backup archive you can use the Android Backup Extractor. It converts the Android backup archive to a tar archive file.
Note: If the app specifies in it's manifest that backup is disallowed the described way does not work. In such a case the only way is to root the phone.
You have to navigate to your file with adb shell.
Then copy to sdcard:
cat yourfile > /sdcard/yourfile
Then exit from adb shell and now you can pull:
adb pull /sdcard/yourfile
I need get SQLite database from Android app from Genesis device where user has populated by hand.
How I can create another app or any other way to get this db and save in place where I can get?
obs.: the device has root
Thanks
Steps from .../platform-tools of Android on cmd:
1) type adb shell
2) run-as com.your.package
3) type ls
cache
databases
lib
You can find Your Database Here...Also You didn't even have to root the Device
Hope this could helpful for you...
Provided you have the device attached to a box with adb on the PATH you can use this command:
adb -d shell 'run-as your.package.name.here cat /data/data/your.package.name.here/databases/your_db_name_here.sqlite > /sdcard/recovered_db.sqlite'
Or you can use Ecliplse DDMS file explorer.
VERY EASY WAY TO DO IT
In the latest releases of Android Studio (I am using AS v3.1.2) the Google team has made it really straight forward. You just have to open the Device File Explorer window which should be at the bottom of the right vertical toolbar, if you cannot find it you can also open it this way:
View -> Tool Windows -> Device File Explorer
Once you have Device File Explorer window open, use your mouse to navigate to the following path:
data -> data -> your.package.name -> databases
Inside the databases folder you should see the database you want to explore, do a right click and Save As... select your desired computer destination folder and voila!!
You can either include the Stetho library on your app,
http://facebook.github.io/stetho/
which will allow you to access your DB using Chrome's Web Debug tools
or use the following shell script:
#!/bin/bash
echo "Requesting data from Android"
adb backup -f data.ab -noapk YOUR.APK.NAME
echo "Decoding...."
dd if=data.ab skip=24 iflag=skip_bytes | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf -
rm data.ab
echo "Done"
```
None of the methods above require your device to be rooted and the latter works even on apps that you did not write yourself, as long as the ApplicationManifest.xml does not contain "backup=false"
After trying dozens of commands that didn't work for me on Marshmallow, I've found this one that works (for debuggable apps at least):
adb shell "run-as your.package.name cp /data/data/your.package.name/databases/you-db-name /sdcard/file_to_write"
Then you simply can view the DB with aSQLiteManager for instance.
You can use this script.
humpty.sh
You should know the application package name and sqlite database name.
You can check the available databases.
$ adb shell
$ run-as <package-name>
$ ls databases/
To dump database or other file.
./humpty.sh -d <package-name> databases/<db-name>
I am trying to reach the sqlite database on my device using the procedure described here: How can i see SQLite Database (No emulator)?
However, I keep on getting sqlite3 not found.
I assume I am meant to be entering the commands with the hash (#) sign at the start of the line.
I tried with it and got nothing.
Without it I get the error message.
The sqlite3.exe file is definitely there and in the path.
Do I have to install something?
Some manufacturers deliver the devices without sqlite being installed on them. You can copy the sqlite program though from a emulator to your device if the device has an arm processor.
Start the emulator and use the adb command from the platform-tools in android-sdk
adb pull /system/xbin/sqlite3
Mount the system partition of your device read/write after this tutorial:
http://android-tricks.blogspot.com/2009/01/mount-filesystem-read-write.html
Use the adb command to copy the sqlite3 file to your device
adb push sqlite3 /system/xbin/
After you reboot your device the sqlite3 command should work.
Edit (copy from linked page - in the case link becomes invalid). The instructions for step 2 are:
adb shell
su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
"Replace /dev/block/mtdblock3 & /system with appropriate device path and mount point, as obtained from cat /proc/mounts"
Go to Play store --> search for Titanium Backup & install it
adb shell
su
cp /data/data/com.keramidas.TitaniumBackup/files/sqlite3 /system/xbin/
cd /system/xbin/
chmod 755 sqlite3
adbd reboot (just in case)
Enjoy the result
For those who, like me, couldn't use Sqlite3, I used a workaround for this:
cat srcfile> / mnt / sdcard / dstfile
With this you can put the files into an external .db manager.
I need a way to install or somehow get access to sqlite3 in the adb shell. I have rooted my device.
I've tried to find an answer but the closed I could come is:
Why do I get a "sqlite3: not found" error on a rooted Nexus One when I try to open a database using the adb shell?
But I don't think it's good idea to push my windows sqlite3.exe on a linux system?
So is it possible to install the sqlite3 terminal browser somehow?
[SOLUTION]
From the different comments and some asking around at #android-dev (irc), I found a solution. First I copied the database file to my desktop. But fist I had to install BusyBox, because cp isn't included?!? After that ran I into the problem that I couldn't pull or push from anywhere but /sdcard/ . I could then use /sdcard/ as a "middle station" and pull/push my db.
Then I got exhausted! I really had to have my sqlite terminal explore. Then I got the idea to start the emulator pull the sqlite binary from /system/xbin/sqlite3. Then remount /system with rw:
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
and push sqlite to the /sdcard/, and from there copy it to /system/xbin/
Now it works :D
Download this app from google play will help you install sqlite3 on android https://play.google.com/store/apps/details?id=ptSoft.util.sqlite3forroot
You don't need root to pull the database from your device. Simply run the following commands:
adb shell run-as <package-name> "cp databases/<db_name>.db /sdcard/ && exit"
adb pull /sdcard/<db_name>.db ~/Downloads/
From there, you can use sqlite3 for whatever operating system you're using (http://www.sqlite.org/download.html), or a sqlite browser such as "DB Browser for SQLite" (http://sqlitebrowser.org/)
I use Rajath's technique... Adb "Pull" the db from the emulator/device, work on it, then adb "push" it back onto/into the emulator device.
also:
I use the free SQLite Editor from the Android Market. I have not rooted my LG Ally and therefor can only edit database tables on my sdcard with SQLite Editor.
Rajath suggests using the adb to push and pull the databases to and from the emulator/device. The work on the database with the windows (or whatever) sqlite3 program you have. He does not suggest pusing the windows sqlite3 onto the Android device, IMHO.
I note that java/android "query()" sends actual SQL commands programmacitacly to ones program with user input. I conclude that sqlite3 is in Android somewhere.
When using the emulator Dev Tools is available, and way down at the bottom of the list is the Terminal Emulator. This allows exploration of file structure of Android in the emulator. However using "adb shell" from the PC has root permissions.
good luck. cactus mitch
You can do this with adb shell without issue.
In terminal or CMD (assuming you have the ADB path set and your phone has ROOT) type:
$ adb shell
$ cd data/data/com.nameofyourpackage/databases/
$ ls to find the name of your database
$ sqlite3 nameofyourdb.db
Then you can use .tables .schema to see the data you need to create the appropriate query.