Unable to open a realm at path 3.7.1
'io.realm:realm-gradle-plugin:3.7.1'
I'm getting the following crash
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app/com.app.activities.startup.StartUpActivity_}: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.app/files/default.realm': Bad Realm file header (#1). (Bad Realm file header (#1)) (/data/data/com.app/files/default.realm) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 90 Kind: ACCESS_ERROR.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.app/files/default.realm': Bad Realm file header (#1). (Bad Realm file header (#1)) (/data/data/com.app/files/default.realm) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 90
at io.realm.internal.SharedRealm.nativeGetSharedRealm(SharedRealm.java)
at io.realm.internal.SharedRealm.(SharedRealm.java)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:227)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:217)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:317)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:281)
at io.realm.Realm.getDefaultInstance(Realm.java:325)
at com.app.activities.SuperActivity.onCreate(SuperActivity.java:73)
at com.app.activities.startup.StartUpActivity.onCreate(StartUpActivity.java:151)
at com.app.activities.startup.StartUpActivity_.onCreate(StartUpActivity_.java:46)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
@Override
public void onCreate() {
Realm.init(this);
RealmConfiguration newConfig = new RealmConfiguration.Builder().schemaVersion(2).deleteRealmIfMigrationNeeded().build();
Realm.setDefaultConfiguration(newConfig);
Realm.compactRealm(Realm.getDefaultConfiguration());
}
Are you using compact? Because then you might be running into this issue: https://github.com/realm/realm-java/issues/5011
Yes I am! The last line in my on create method
I always feel kinda scared when I see compact in Application, is that operation multi-process safe? @cmelchior
Not sure if this is related or if it should be a separate issue, but i'm seeing a similar error coming from the same o_realm_internal_SharedRealm.cpp line 90.
Crashlytics link: http://crashes.to/s/33e767be94c
@DejanRistic I think this essentially means that the file was manually deleted while it was already open?
@Zhuinden Yes, it should be fully processed safe. @trr-amsiq Ok, then most likely you are running into #5011 . It should only happen if the device is running out disk space, but that still doesn't make it acceptable. We have a fix merged and will release it as soon as we can.
I'll fold this issue into #5011. Closing