Import default.realm on Android

Hello,

Im using the .NET SDK with Unity, I want to “prepopulate” the realm database, copy it into the Ressouces Folder, so I can load the Database at the first startup on the Android device.

I got this working inside the unity editor, however it does not work on Android.

        string databasePath = Path.Combine(Application.persistentDataPath, databaseFileName);

        if (!File.Exists(databasePath))
        {
            // If the database doesn't exist, copy the prepopulated database from Assets
            TextAsset prepopulatedDatabase = Resources.Load<TextAsset>(defaultName);
            if (prepopulatedDatabase != null)
            {
                File.WriteAllBytes(databasePath, prepopulatedDatabase.bytes);

Its using the correct path, but after Realm.GetInstance();
I cannot find any Data created before.

Any solution or workaround to deliver a Database that is already filled with Data on the first startup?

Thanks!

When you copy the file, is it the correct size? Also, can you open it with a different tool - e.g. Realm Studio? Finally, is your database encrypted by any chance? The encryption page size differs between operating systems, so it’s not guaranteed that an encrypted file created on one OS will be readable on another.