1

The sqlite base file is stored in path data/data/my-package-name/databases/mybase.db (Where does Android emulator store SQLite database?)

Sometimes, i get this file on a remote real device and i would like to copy it to android emulator on my Android Studio for debugging. In other words, i want that my application on Android Studio uses this base. How can i do it?

Another possibility: how to copy this base to a my real device who is connected to PC by USB cable

thanks a lot, regards

forpas
  • 160,666
  • 10
  • 38
  • 76
dsea
  • 75
  • 3
  • 16

1 Answers1

5

Start your emulator.
Open Device File Explorer (a tab button at the bottom right side of Android Studio).
Go to the folder data/data/my-package-name/.
If there is no subfolder databases then create it by right clicking on the my-package-name folder and then New->Directory where you type databases and click OK.
Now right click on the folder databases and click Upload....
Navigate to the SQLite file that you want to copy, select it and click OK.

forpas
  • 160,666
  • 10
  • 38
  • 76
  • Good answer, I would like to add in some cases (at least for me), databases are not `.db` files but `.sqlite` files, I don't know if you can use a different file extension. – stramin Jan 24 '20 at 17:07
  • 1
    You can upload any file to the `databases` subfolder. Also it makes no difference if your database has an `.sqlite` extension as long as it is a valid sqlite database. You access the database from code where you usually declare the (full) name of the database as a static variable. – forpas Jan 24 '20 at 17:13
  • Watch out, if you don't close your database properly on Later Android Version the data will be in the WAL file (Write Ahead Logging). You would need to copy the WAL file and the database file or make sure your App fully closes the database or disable Write Ahead Logging. – Andrew Jan 24 '20 at 20:45