Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac, Android Studio, Emulator, SQLite database - actually find directory?

I am using Android Studio on a Mac, everything on the latest version. Say I do this:

SQLiteDatabase db;
db = yourAppContext.openOrCreateDatabase("db.sqlite3", Context.MODE_PRIVATE, null);

Thanks to this link:

http://www.c-sharpcorner.com/UploadFile/e14021/know-where-database-is-stored-in-android-studio/

it's possible to exactly find the directory holding your actual SQLite3 database on the emulator as it runs:

enter image description here

Great stuff.

Next you can click the Pull button, and pull that file to say your desktop on the Mac. Awesome.

But, how do you actually find literally that folder ("databases" in the example), on your Mac?

i.e., using a normal shell terminal, I want to "cd" to there.

Where is that folder, in the ordinary 'nix file structure of the host Mac computer?

like image 861
Fattie Avatar asked Jan 06 '17 02:01

Fattie


People also ask

Where are SQLite databases stored Mac?

SQLite is included in macOS and Mac OS X by default. It is located in the /usr/bin directory and called sqlite3. Using SQLite, users can create file-based databases that can be transported across machines, platforms, etc.

How do I access SQLite database on Mac?

If you are using Linux or a Mac, open a terminal window instead a command prompt. Open a command prompt (cmd.exe) and 'cd' to the folder location of the SQL_SAFI. sqlite database file. run the command 'sqlite3' This should open the SQLite shell and present a screen similar to that below.


2 Answers

adb (Android Debug Bridge) is needed to access an emulator device's filesystem via the command-line . If you don't already have it installed you can download it here.

Once installed it's just a matter of using a few commands to view/access the files:

  1. Open Terminal.app.
  2. Execute adb devices (this should list your current emulator devices).
  3. Connect to the emulator device with adb shell .
  4. Change directory cd to the folder where your app databases are.
  5. Type ls to see which database files are present.

In Terminal it would look something like this:

List the emulator devices:

$ adb devices
List of devices attached
emulator-5554  device

Connect to device with adb shell:

$ adb -s emulator-5554 shell

Change directory (cd) into it's SQLite3 database location (package name is usually com...):

adb shell
$ cd /data/data/<your app package name>/databases/

List the files in the databases directory:

adb shell
$ ls
db.sqlite3

That's really the basics of it! It's also possible to push/pull to copy files from the emulator (remote) to your (local) filesystem:

adb pull /data/data/com.yourpackagename.app/databases/db.sqlite3 /local/save/path

If Permission is denied run ADB in root mode:

adb root

More information:

  • Android Studio Command-Line Reference
  • Android Studio Command-Line SQLite3
  • Android Studio SDK Platform Tools
like image 101
l'L'l Avatar answered Oct 14 '22 04:10

l'L'l


or you can pull databases using this command

adb pull /data/data/com.application/databases/ for example adb pull /data/data/com.zameen.propforce/databases/

secondly that folder is not accessible unless your device is rooted or you are using emulator

if your device is rooted. you get super user access by adb su command then you can go to this directory

like image 42
Abdullah Raza Avatar answered Oct 14 '22 03:10

Abdullah Raza