realm-java: io.realm.exceptions.RealmFileException when launching application
I have researched many and many times about this issue but I have not found any solution. I am implementing an Android application with Realm Android 3.0 and using Fabric to find out crash report. Below is Realm initialize code in Application class:
Realm.init(this);
RealmConfiguration config = new RealmConfiguration.Builder().name(REALM_SCHEMA_NAME)
.schemaVersion(REALM_SCHEMA_VERSION)
.migration(new Migration())
.build();
Realm.setDefaultConfiguration(config);
Realm realm = Realm.getDefaultInstance(); // Automatically run migration if needed
realm.close();
I get many crash report from Fabric related with io.realm.exceptions.RealmFileException
such as:
- Unable to open a realm at path ‘/data/data/com.xxx/files/xxx.realm’: Incompatible histories.
- Unable to open a realm at path ‘/data/data/com.xxx/files/xxx.realm’: bad realm file header (#3). (bad realm file header (#3))
- Unrecoverable error. mmap() failed: Out of memory size xxx
- etc …
So, can you tell me the reason of this issue? Thank you.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 73 (34 by maintainers)
Only
Realm.getInstance()
.Realm.init()
just load and setup the Realm library, so it isn’t connected to opening any files.Realm.getInstanceAsync()
+Realm.Builder.compactOnLaunch()
will be the my choice if I want to do that. But it depends on your use case if you can manage the app’s life cycle well.compact()
should reclaim disk space which is not being used including the case you mentioned. See https://realm.io/docs/java/latest#faq-large-realm-file-sizecompact operation may take some time to finish depends on how much valid data stared. Consider to use those APIs
https://realm.io/docs/java/4.3.1/api/io/realm/RealmConfiguration.Builder.html#compactOnLaunch--
https://realm.io/docs/java/4.3.1/api/io/realm/Realm.html#getInstanceAsync-io.realm.RealmConfiguration-io.realm.Realm.Callback-
@jollyjoker992 Compacting a Realm will removed other versions and other unused space in the Realm file. Most databases have such a function (in PostgreSQL it is called
VACUUM
). We don’t support online compaction so doing it a launch after the app has been killed sounds like a good time to do it.@jollyjoker992 No exact date but we will probably do a release in a week or two (we don’t have fixed date as support load or critical bugs are hard to predict).
@jollyjoker992 With #4559 merged, you can try a snapshot release and see if it solves your issue.
A possible fix for I think this error is being investigated in https://github.com/realm/realm-java/pull/4559