I want to read some initial data from Realm database file when starting the application (Android), but I do not understand why database file is not copied over. I followed Bundle a Realm File tutorial - created and put bundle.realm
file in android/app/src/main/assets/
, added path
attribute with value bundle.realm
and call Realm.copyBundledRealmFiles()
before creating Realm context. Anyway, from realm.path
I found out that it looks for database file in /data/data/com.<app name>/files/bundle.realm
, where it does not exist. I can upload it manually though Device File Explorer, but I expected that Realm.copyBundledRealmFiles()
would copy the file where it’s supposed to be.
What do I need to change to read from existing Realm file automatically?
Here is a relevant code segment:
database.ts
import { TimeSeriesData } from './models';
import { Realm, createRealmContext } from '@realm/react';
Realm.copyBundledRealmFiles();
const { RealmProvider, useRealm, useObject, useQuery } = createRealmContext({
schema: [TimeSeriesData],
path: 'bundle.realm',
});
export { RealmProvider, useRealm, useObject, useQuery };