io.realm.exceptions.RealmFileException
How frequently does the bug occur?
Always
Description
My app seems to be crashing on a Google pixel 8 (Android 14) every time it starts and io.realm.exceptions.RealmFileException is logged and it seems to be only happening on the app published on play store if I build from Android studio the crash does not occur. This is my realm initialization class
import android.content.Context
import io.realm.Realm
import io.realm.RealmConfiguration
class DatabaseService(context: Context) {
init {
Realm.init(context)
}
val realmInstance: Realm
get() {
val config = RealmConfiguration.Builder().name(Realm.DEFAULT_REALM_NAME)
.deleteRealmIfMigrationNeeded().schemaVersion(4).build()
Realm.setDefaultConfiguration(config)
return Realm.getInstance(config)
}
}
Stacktrace & log output
Exception io.realm.exceptions.RealmFileException:
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm
at io.realm.internal.OsSharedRealm.<init> (OsSharedRealm.java:175)
at io.realm.internal.OsSharedRealm.getInstance (OsSharedRealm.java:260)
at io.realm.BaseRealm.<init> (BaseRealm.java:142)
at io.realm.BaseRealm.<init> (BaseRealm.java:109)
at io.realm.Realm.<init> (Realm.java:161)
at io.realm.Realm.createInstance (Realm.java:535)
at io.realm.RealmCache.createInstance (RealmCache.java:508)
at io.realm.RealmCache.doCreateRealmOrGetFromCache (RealmCache.java:461)
at io.realm.RealmCache.createRealmOrGetFromCache (RealmCache.java:422)
at io.realm.Realm.getInstance (Realm.java:464)
at org.ole.planet.myplanet.datamanager.DatabaseService.getRealmInstance (DatabaseService.kt:17)
at org.ole.planet.myplanet.service.UploadToShelfService.uploadUserData (UploadToShelfService.kt:45)
at org.ole.planet.myplanet.service.AutoSyncWorker.onError (AutoSyncWorker.kt:95)
at org.ole.planet.myplanet.datamanager.Service$checkVersion$1$onResponse$1.onResponse (Service.kt:148)
at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.lambda$onResponse$0$retrofit2-DefaultCallAdapterFactory$ExecutorCallbackCall$1 (DefaultCallAdapterFactory.java:89)
at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1$$ExternalSyntheticLambda0.run (D8$$SyntheticClass)
at android.os.Handler.handleCallback (Handler.java:958)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:205)
at android.os.Looper.loop (Looper.java:294)
at android.app.ActivityThread.main (ActivityThread.java:8248)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:971)
### Can you reproduce the bug?
No
### Reproduction Steps
**APK build from Android studio**
https://github.com/open-learning-exchange/myplanet/releases/download/v0.14.21-lite/myPlanet.apk
**APK on playstore**
https://play.google.com/store/apps/details?id=org.ole.planet.myplanet
**Link to GitHub repo**
https://github.com/open-learning-exchange/myplanet
### Version
10.18.0
### What Atlas App Services are you using?
Local Database only
### Are you using encryption?
No
### Platform OS and version(s)
Google pixel 8 Android 14
### Build environment
Android Studio version: Iguana | 2023.2.1
Android Build Tools version: 28.0.0
Gradle version: 8.4
➤ PM Bot commented:
Jira ticket: RJAVA-1253
@Okuro3499 Thank you for reporting.
Do you expect a schema migration? If so, the file will be deleted, and the schema version will be set to zero. What if you remove schemaVersion(4) - will you still see the exception?
I still get the same exception
@Okuro3499 Hmm, usually RealmFileException should have some more details about what is going on. Can it be that there is a file on the device when you throught play store, but not when you test it locally?
Seems like you are initializing the default configuration each time you call the get-ter of realm. You should probably just initialize and default configuration in init and then obtain the actual instance when calling get:
init {
Realm.init(context)
val config = RealmConfiguration.Builder()
.name(Realm.DEFAULT_REALM_NAME)
.deleteRealmIfMigrationNeeded().schemaVersion(4).build()
Realm.setDefaultConfiguration(config)
}
val realmInstance: Realm
get() {
return Realm.getInstance()
}
Not sure it has anything to do with your issue, but could be have an impact dependent on the rest of your realm-usage throughout the app.
Maybe try enabling logging in init with:
RealmLog.setLevel(LogLevel.DEBUG);
And see if you can catch more info on the error ... or post the output here for us to interpret it.
@rorbech I implemented as you advised and app still crashes on the device but log remains the same for the crash. checked the device and there is no new file created on the device when you downloaded through play store
class DatabaseService(context: Context) {
init {
Realm.init(context)
RealmLog.setLevel(LogLevel.DEBUG)
val config = RealmConfiguration.Builder()
.name(Realm.DEFAULT_REALM_NAME)
.deleteRealmIfMigrationNeeded()
.schemaVersion(4)
.allowWritesOnUiThread(true)
.build()
Realm.setDefaultConfiguration(config)
}
val realmInstance: Realm
get() {
return Realm.getDefaultInstance()
}
}
error is still same and only one type of device is still affected
Exception java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3946)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:4126)
at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:108)
at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem (TransactionExecutor.java:195)
at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:157)
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:90)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2544)
at android.os.Handler.dispatchMessage (Handler.java:107)
at android.os.Looper.loopOnce (Looper.java:232)
at android.os.Looper.loop (Looper.java:317)
at android.app.ActivityThread.main (ActivityThread.java:8501)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:878)
Caused by io.realm.exceptions.RealmFileException:
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm
at io.realm.internal.OsSharedRealm.<init> (OsSharedRealm.java:175)
at io.realm.internal.OsSharedRealm.getInstance (OsSharedRealm.java:260)
at io.realm.BaseRealm.<init> (BaseRealm.java:142)
at io.realm.BaseRealm.<init> (BaseRealm.java:109)
at io.realm.Realm.<init> (Realm.java:161)
at io.realm.Realm.createInstance (Realm.java:535)
at io.realm.RealmCache.createInstance (RealmCache.java:508)
at io.realm.RealmCache.doCreateRealmOrGetFromCache (RealmCache.java:461)
at io.realm.RealmCache.createRealmOrGetFromCache (RealmCache.java:422)
at io.realm.Realm.getDefaultInstance (Realm.java:443)
at org.ole.planet.myplanet.datamanager.DatabaseService.getRealmInstance (DatabaseService.kt:22)
at org.ole.planet.myplanet.ui.sync.SyncActivity.onCreate (SyncActivity.kt:151)
at org.ole.planet.myplanet.ui.sync.DashboardElementActivity.onCreate (DashboardElementActivity.kt:45)
at org.ole.planet.myplanet.ui.dashboard.DashboardActivity.onCreate (DashboardActivity.kt:79)
at android.app.Activity.performCreate (Activity.java:8767)
at android.app.Activity.performCreate (Activity.java:8745)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1519)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3928)