realm-java: Exception : Invalid format of Realm file.

I’m using realm for databse processingin my android project. And I got some user’s report about the crash:

java.lang.IllegalArgumentException: Illegal Argument: Invalid format of Realm file.
at io.realm.internal.SharedGroup.createNativeWithImplicitTransactions()(SourceFile:-2)
at io.realm.internal.SharedGroup.<init>()(SourceFile:64)
at io.realm.internal.SharedGroupManager.<init>()(SourceFile:49)
at io.realm.BaseRealm.<init>()(SourceFile:77)
at io.realm.Realm.<init>()(SourceFile:138)
at io.realm.Realm.createAndValidate()(SourceFile:269)
at io.realm.Realm.createInstance()(SourceFile:249)
at io.realm.RealmCache.createRealmOrGetFromCache()(SourceFile:114)
at io.realm.Realm.getInstance()(SourceFile:213)

I never face the crash while developing but seems that my user got it many times. Below is my implementation which crash was detected:


private Realm getRealmFromConfig(Context context) {
    RealmConfiguration config = getRealmConfigByDBName(context, databaseName);
    Realm.compactRealm(config);
    return Realm.getInstance(config);
}

public RealmConfiguration getRealmConfigByDBName(Context context, String dbName) {
    RealmConfiguration config = new RealmConfiguration.Builder(context)
            .name(dbName)
            .schemaVersion(1)
            .setModules(new Module())
            .deleteRealmIfMigrationNeeded()
            .build();
    return config;
}

Details

The crash log points out that crash occur in line return Realm.getInstance(config);

I have a look at Realm.java file but still can not get any more information which related to message Invalid format of Realm file. So any one can help to give me a solution or workaround which can resolve the problem or some theory about why crash occurs.

Thanks for helping

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

In last 30 days this crash hit 146 times for 8 different users! Happened in all android versions 4,5 and 6!

In onCreate() of App.java I init realm like this

RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(App.this)
                .schemaVersion(10)
                .migration(talkootMigration)
                .name("db")
                .build();
 Realm.setDefaultConfiguration(realmConfiguration);
 Realm.compactRealm(realmConfiguration);

In my activity’s onCreate() method I create realm instance as follows,

mRealm = Realm.getDefaultInstance();
mRealm.setAutoRefresh(true);

Crash starts from this line ‘mRealm = Realm.getDefaultInstance()’ from onCreate() of activity. I don’t have any more information from the crash log or from users.

I couldn’t reproduce this bug on my own. But my few of my users are experiencing it. But those who experiences this. experience this multiple times.

Any help would be appreciated. And sorry I can’t share you the entire source code.