Realm file as resource: migration really needed?

64 views
Skip to first unread message

Frane Bandov

unread,
Oct 21, 2015, 1:01:38 PM10/21/15
to Realm Java
Hi,

I am working on pre-filled Realm file, which shares some static data between my Android and iOS app. 
Following this iOS approach https://realm.io/docs/objc/latest/#bundling-a-realm-with-an-app and setting the instance to readonly everything works fine.

For Android I tried following almost the same approach and the comment posted here: https://stackoverflow.com/questions/29839740/how-to-deliver-app-with-prefilled-realm-database#comment54307811_29854659
I'm including the Realm file as a resource and copy it over to the context file directory. However, if try to open the file without migration like this

Realm.getInstance(new RealmConfiguration.Builder(context).name("directory.realm").build())

i get the exception:
RealmMigrationNeededException

If I just add a pseudo-migration like this

Realm.getInstance(new RealmConfiguration.Builder(context).migration(new RealmMigration() {


            @Override


            public long execute(Realm realm, long version) {


                return ++version;


            }


        }).name("directory.realm").build());



everything works.

The "directory.realm" file is generated by a little OSX script and has no versions and no migration should be necessary.

So my question is: Why is this migration step needed?
I don't really care about the versioning of this file since it's supposed to be readonly and replaced with every new version.
The RealmMigrationNeededException, the mandatory migration and my resulting pseudo-migration feel a little hacky.
Is there a better way of doing this?

Regards,
Frane

Kenneth Geisshirt

unread,
Oct 21, 2015, 2:04:08 PM10/21/15
to Frane Bandov, realm...@googlegroups.com
Hi,

If you are using Realm for Android version 0.83.0 or later, you get the exception due to null support. Null support for the cocoa binding is in its final stages before releasing, so your Android model classes differ slightly from your Cocoa classes. You will get the same exception if your Realm file was created using a version earlier than 0.83.0.

Best,
Kenneth

--
Kenneth Geisshirt
Member of technical staff


--
You received this message because you are subscribed to the Google Groups "Realm Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-java+...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-java/8c7eb441-e930-44e1-a347-775fa0704d33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



{#HS:132168084-2099#}
Reply all
Reply to author
Forward
0 new messages