Search code examples
androidadb

adb unable to show / open / connect database


I try to use adb to query my sqlite3 db. I use this db with my app on emulator without any problems, but I'm not able to query it from the adb shell. I have read a lot here and on Android developer guide to understand my problem/error but I have not solved anything.

Here's a trace of what happens when I try to query the database from adb:

adb -s emulator-5554 shell
sqlite3 /data/data/rf.stats/databases/sstatsdb.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .tables
sqlite> select * from games;
SQL error: no such table: games
sqlite> .databases
seq name file
--- --------------- ----------------------------------------------------------
0 main /data/data/rf.stats/databases/sstatsdb.db
1 temp /sqlite_stmt_journals/etilqs_H2EoeecYlb1UK2U

Why can't I query my database from the adb shell, given that it works in the emulator?

I'm on Ububtu Lucid with Android 10.0.1 and Java SDK 6.


Solution

  • adb doesn't have permission to look inside /data on the phone. The emulator doesn't have this restriction. It's part of the security model that prevents people from accessing data belonging to third-party applications.

    There are two ways to get around this:

    • the official way is to set your application as debuggable (by putting android:debuggable="true" in the <application> element in the manifest), and then use DDMS; however, I've never managed to make this work.

    • the unofficial but much more useful way is to jailbreak the phone using something like SuperOneClick. This will let you log in as root with adb, which will then give you full access to all data on the phone (including your application's).