realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

App crashes with FORMAT_UPGRADE_REQUIRED while using Realm 7.0.0

Open 73sravanthi opened this issue 6 years ago • 82 comments

We have been using Realm from the past year, We recently upgraded the application from V6.1.0 to V7.0.0, post this upgrade we are witnessing the crash mentioned, we are using Kotlin for application development with Realm java and lastly, we have enabled DB encryption

Process: com.com.myapp.Application.qa, PID: 31558 java.lang.RuntimeException: Unable to create application com.myapp.Application: io.realm.exceptions.RealmFileException: Opening Realm files of format version 0 is not supported by this version of Realm (Database has an unsupported version and cannot be upgraded Exception backtrace: (/data/data/com.myapp.Application:/files/myapp.realm) in /Users/cm/Realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 107 Kind: FORMAT_UPGRADE_REQUIRED. at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(Native Method) at io.realm.internal.OsSharedRealm.(OsSharedRealm.java:175) at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:251) at io.realm.BaseRealm.(BaseRealm.java:137) at io.realm.BaseRealm.(BaseRealm.java:104) at io.realm.Realm.(Realm.java:163) at io.realm.Realm.createInstance(Realm.java:499) at io.realm.RealmCache.createInstance(RealmCache.java:507) at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:473) at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:414) at io.realm.Realm.getDefaultInstance(Realm.java:407)

73sravanthi avatar May 31 '20 07:05 73sravanthi

How are you opening the Realm?

cmelchior avatar May 31 '20 15:05 cmelchior

DB configuration :
RealmLivedataWrapper.init(context) val config = RealmConfiguration.Builder() .name(BuildConfig.REALM_FILE_NAME) .modules(Realm.getDefaultModule(), DataRealmModules()) .encryptionKey(StorageKeyUtils.getKey(sharedPreferences, context)) .schemaVersion(BuildConfig.REALM_SCHEMA_VERSION) .migration(DbMigration()) .build() Realm.setDefaultConfiguration(config)

realmLivedataWrapper = RealmLivedataWrapper.Builder()
  .setRealmConfiguration(config)
  .build()

While navigating between the modules its crashing at val realm: Realm = Realm.getDefaultInstance()

73sravanthi avatar May 31 '20 17:05 73sravanthi

Weird. The error message seems to indicate that you are opening an older already existing file. Is that the case?

cmelchior avatar May 31 '20 17:05 cmelchior

It's crashing while navigating from one module to another after some modifications. We have used Realm v6.1.0. This issue is observed when upgraded to v7.0.0 .

73sravanthi avatar May 31 '20 17:05 73sravanthi

The same scenario is working fine with Realm v6.1.0

73sravanthi avatar May 31 '20 17:05 73sravanthi

Will there be any issue if we use following method in 7.0.0

val realm: Realm = Realm.getDefaultInstance() realm.sharedRealm.refresh() try { realm.executeTransaction { realmInstance -> realmInstance.copyToRealmOrUpdate(dataObjects) } } catch (ex: Exception) { Log.d("DOWNLOAD_ERROR", "storeToLocal DB store EXCEPTION") Log.d(this::class.java.simpleName, ex.message) } finally { realm.refreshAndClose() }

73sravanthi avatar Jun 01 '20 09:06 73sravanthi

Hi.Any update on the above issue? We are facing the above crash with above error in multiple places .

73sravanthi avatar Jun 01 '20 15:06 73sravanthi

I have noticed this error too. We have only upgraded realm version and did not touch schema itself. Mostly it occurs on Android 10 devices. Most popular devices which failed to upgrade:

Samsung Galaxy A70
Xiaomi Mi9 SE
Nokia 5

Other devices seemed to work fine, but this is quite critical.

edgar-zigis avatar Jun 23 '20 10:06 edgar-zigis

Exactly the same issue on our side, reproduced on my Pixel 3 on Android 9.

ganfra avatar Jun 24 '20 14:06 ganfra

@ganfra Can you share how to reproduce? If you want to keep it private you can email me at [email protected]

cmelchior avatar Jun 24 '20 14:06 cmelchior

If you are brave enough you can test it on our open-source project: https://github.com/vector-im/riotX-android Updating realm to 7.0.0, then after some initial launches it will crash with this issue. (Also, not related at all, but we are having massive performance issues when db is getting big)

ganfra avatar Jun 26 '20 08:06 ganfra

So I created a test account where you will be able to reproduce the error: Login: realm7 Password: realm7.0help

You should use the develop branch.

So here is how to reproduce

  1. compile the app with realm 6.1.0 (in the matrix-sdk-android gradle file).
  2. launch and log in with given credentials.
  3. Compile the app with realm 7.0.0
  4. Relaunch the app, use the app a bit.
  5. kill the app and relaunch => it should crash. If not, kill and relaunch until it crashes

Tell me if you need more information :)

ganfra avatar Jun 26 '20 13:06 ganfra

@cmelchior : any chance you could look at it?

ganfra avatar Jun 30 '20 09:06 ganfra

@ganfra Thank you for the project. I am able to reproduce the problem. We are looking into it.

A few things ruled out:

  • It isn't a wrong encryption key causing this issue or lack of key completely.

cmelchior avatar Jul 01 '20 12:07 cmelchior

Did you have any lead on what could be wrong?

ganfra avatar Jul 07 '20 11:07 ganfra

@cmelchior Would appreciate any update on this. Unfortunately, we too face this issue after upgrading from v6.1.0 to v7.0.0. It has resulted into hundreds of crashes reported in Firebase in barely few hours.

patelnishantk avatar Jul 17 '20 05:07 patelnishantk

@patelnishantk Unfortunately we still don't have a root cause for this.

cmelchior avatar Jul 17 '20 06:07 cmelchior

We are experiencing the same issue with a single client.

ppamorim avatar Aug 01 '20 15:08 ppamorim

@cmelchior We are going to extract the user database and analyse it to see if it's the realm running in the device that cannot open it or if the realm file is corrupted.

ppamorim avatar Aug 04 '20 14:08 ppamorim

We got the Realm file and when opening it on Realm Studio, we get the very same error:

Screenshot 2020-08-05 at 10 49 13

ppamorim avatar Aug 05 '20 09:08 ppamorim