react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

How to find Database file location in React native app - Andriod

Open Aravindhan12 opened this issue 7 years ago • 18 comments

I have created and stored values in the database. I just want to know the db file size & view the contents of the database. In case of native Android app, I can view the db file through Andriod device monitor in Android Studio. Can anyone help me in finding the location of the Sqlite database in React native andriod?

Aravindhan12 avatar Jan 30 '18 05:01 Aravindhan12

Would really like to know how to do this as well. There's nothing in /Android/data/com.whatever.appname/

bitfabrikken avatar Mar 27 '18 08:03 bitfabrikken

Did you guys find out where the .db is?

Jorgee97 avatar Apr 27 '18 03:04 Jorgee97

I want to know too! -_-

Adcrazynoga avatar May 08 '18 10:05 Adcrazynoga

You need to have Root access (not that difficult with an emulator) and access /data/data/{your.app.folder}/databases, I don't know if there's another way but that worked for me

gabyckaz avatar Jul 04 '18 21:07 gabyckaz

You don't need to have a root access if you the version of the App is debug. use

run-as your.package

The database is located in the databases folder. If you have an access to the release keychain you could even replace the release version of the app by the debug version signed with the release key and get needed access.

dryganets avatar Oct 29 '18 21:10 dryganets

i also want to know where is database file in react native. sqlite

Waqas-Jani avatar Sep 19 '19 11:09 Waqas-Jani

@dryganets , how to use this command in cmd .. ?? run-as your.package

Waqas-Jani avatar Sep 19 '19 11:09 Waqas-Jani

adb shell runs the shell

in shell run: run-as package-name

It automatically redirect you to the application folder. Runls databases to output the list of files.

if you want to copy the file to sdcard cat filename.db > /sdcard/filename.db exit the shell session and run adb pull /sdcard/filename.db

The database file name is exact to the name you passed in the js code.

dryganets avatar Oct 02 '19 19:10 dryganets

This code help me here to get db :

adb -d shell "run-as com.dautechnology.abdimuna.smartparking cat /data/data/<myAppPackageName>/databases/<databaseFileName> > /sdcard/<databaseFileName>"

The above command will store file to /sdcard You can verify the file by adb shell ls sdcard/ Then exit from adb shell by typing exit

alipm avatar Apr 23 '20 16:04 alipm

https://stackoverflow.com/questions/34372057/where-is-asyncstorage-data-physically-located-on-android-devices/43781842#43781842

RandunuK avatar Apr 26 '20 10:04 RandunuK

Is there away to get the location via react native?

I need to find the location, upload the sqlite file to remote server for bug report purposes thanks.

alan-la-chen-478 avatar Oct 10 '20 03:10 alan-la-chen-478

Created separate posts for how to delete the database and how to check DB file location on user phone.

https://infinitbility.com/how-to-delete-sqlite-database-in-android-react-native

infinitbility avatar Nov 29 '20 18:11 infinitbility

please i want to know, where i find location .sqlite file. with react-native

hidayatridwan avatar Feb 03 '21 05:02 hidayatridwan

please i want to know, where i find location .sqlite file. with react-native

You get sqlite_db_name.db file on your Android/data/com.projectname/ databases folder.

You can also check using rn-fetch-blob


import RNFetchBlob from 'rn-fetch-blob';
const dirs = RNFetchBlob.fs.dirs;

RNFetchBlob.fs.ls(dirs.MainBundleDir + '/databases').then((files) => {
    console.log(files)
});


Code Snippet from below documentation

https://infinitbility.com/how-to-delete-sqlite-database-in-android-react-native

infinitbility avatar Feb 03 '21 05:02 infinitbility

When Launch succeeded: In Device File Explorer> data> data> com.nameofyourapp> databases You can also click on the bottom tab of android studio 'Database inspector' to see the database changes in real time.

CarolinaPerezFlores avatar Jul 20 '21 03:07 CarolinaPerezFlores

@CarolinaPerezFlores Thanks. Yes we can export this db from here. and also can open that db file in sqlbrowser software (https://sqlitebrowser.org/ ) Screenshot 2022-04-08 at 2 20 04 PM

PrashenAlumnus avatar Apr 08 '22 08:04 PrashenAlumnus

@alan-la-chen-478 Hey, have you found a solution? I also need to get the db file and send it to the server, but I cannot find a way to do this. Could you please share your solution?

pigpudle avatar Jul 03 '22 18:07 pigpudle

@pigpudle

For me, my app only support android, and this is what i'm using to send debug data to my server. I'm not too sure about ios and where they store it.

export const sendDbReport = async state => {
  let response = await RNFetchBlob.fetch(
    'POST',
    `${appConfig.api_domain}/debug-reports`,
    {
      'Content-Type': 'multipart/form-data',
    },
    [
      {name: 'db', filename: 'database.sqlite', data: RNFetchBlob.wrap(await getDbFilePath())},
      {name: 'info', data: JSON.stringify(await getDebugInfo(state))},
    ],
  );

  return response.json();
};

export const getDbFilePath = async () => {
  let bundleId = await DeviceInfo.getBundleId();
  return `/data/data/${bundleId}/databases/${dbName}`;
};

// dbName is what you put for SQLite.openDatabase args

alan-la-chen-478 avatar Jul 21 '22 00:07 alan-la-chen-478