react-native-fs
react-native-fs copied to clipboard
How to copy files from Android bundle?
Hi.
I am bundling a sqlite3 file with my react-native app.
For iOS, I can access easily by adding the file in XCode, and then access it with RNFS.MainBundlePath (I want to copy it to the Documents area so I can write on it)
How to do this on Android?
i am also bundling sqlite-files with my rn-apps using this practice from react-native-sqlite-storage: https://github.com/andpor/react-native-sqlite-storage/#setting-up-your-project-to-import-a-pre-populated-sqlite-database-from-application-for-ios
have you tried this? works out of the box if everything was done right.
Aren't those instructions for iOS only? I want to do this for Android, my iOS version is working fine.
Got your point now. There is a small sentence stating:
"For Android, the www directory is always relative to the assets directory for the app: src/main/assets"
Putting the database into the assets directory will let you create a database copied over from the prebundled one.
template.sqlite:

let params = { name: DATABASE_NAME + mandantId, createFromLocation: "~template.sqlite" }
if (Platform.OS === 'ios') {
params.location = 'Library';
}
return new Promise((resolve, reject) => {
SQLite.openDatabase(params, (db) => {
__db = db;
__isDatabaseOpen = true;
resolve(db)
}, (err) => reject(err));
})
Ok, will give a try.
Still, regarding my original question, which is to copy files from the app bundle to the dedicated app's space... that is possible with iOS, but for Android, I then assume it is not be cause react-native-fs MainBundlePath doesn't return anything.
On Fri, 6 Oct 2017 at 17:16, Hagen Hübel [email protected] wrote:
[image: screen shot 2017-10-06 at 17 16 11] https://user-images.githubusercontent.com/1758597/31284851-1c423b9a-aaba-11e7-8698-c945f6432151.png
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/itinance/react-native-fs/issues/359#issuecomment-334785001, or mute the thread https://github.com/notifications/unsubscribe-auth/AAgE2AvN3UvvCPjum1Ob5YZpCQne-DxXks5spkRbgaJpZM4Pwmhg .
Ok, will give a try. Still, regarding my original question, which is to copy files from the app bundle to the dedicated app's space... that is possible with iOS, but for Android, I then assume it is not be cause react-native-fs MainBundlePath doesn't return anything.
Did you solve it? Did you manage to open the database? I have a similar problem on android