realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.47k stars 1.75k forks source link

Realm database migration is crashing on Android 7.1.2 #4651

Closed ghost closed 6 years ago

ghost commented 7 years ago

The app is crashing with a realm exception that some tables do not exist in the schema. I made three tables in Realm Database and created the migration for them. The app update(migration) is working for all versions of Android, but for Android 7.1.2 is crashing the app with the mentioned exception.

Expected Results

The app not to crash and for the migration to work as expected.

Actual Results

The app is crashing with RealmException , table X is missing from the schema.

Steps & Code to Reproduce

I had version 1.0 of the app installed on my phone, then I installed the Android 7.1.2 update, then I updated my app to version 2.0 which contains the three new tables I mentioned.

On a phone with 7.1.2 that had no previously installed versions of the app, the installation worked fine (e.g first install).

I was using realm 1.3.0 when this crash occurred. I bumped the version to 3.1.4 and the crash was still happening. Unfortunately, a phone restart fixed the problem and it never reproduced, but this happened on 2 different phones, Nexus 6P and Google Pixel, so it is a major issue.

Version of Realm and tooling

Realm version(s): 1.3.0 and 3.1.4

Realm sync feature enabled: no

Android Studio version: 2.3

Which Android version and device: Google Pixel ; Nexus 6P; Android 7.1.2

bmeike commented 7 years ago

@petronela0306 Could you please supply some code that will drive this?

bmeike commented 7 years ago

@petronela0306 We are going to need to reproduce this, in order to resolve it. Can you supply a test case or something?

ghost commented 7 years ago

Hi, Sorry for the late response. Unfortunately, I cannot provide code sample for this, but as I said, the migration worked on OS versions < 7.1.2

As a test case, it is going to be difficult to reproduce, as I mentioned in the description of the issue, you must have a OS version < 7.1.2, have an app installed , then update your OS to 7.1.2 patch, then update your app to a new version that will contain a realm migration.

kneth commented 7 years ago

We have not yet been able to reproduce it but I believe @zaki50 will give it another shot.

Shakezulla57 commented 7 years ago

I'm having the same issue with the updated emulator in the Android Studio 3 canary release.

nickhaw commented 7 years ago

Hi, This issue has just manifested itself with our app. Steps to experience this:

1 - Install an app with a previous version of Realm and populate with at least one realm object (eg. User object with username, email) 2 - Upload a new version of the app with a more recent version of Realm (no change to model so no migration required) 3 - Update the app with new version (crashes begin)

IMP: This only occurs when an update is rolled out from Google Play. ie. Performing these steps in your dev environment will not cause the app to crash. Seems to be affecting devices running Android 7+

cmelchior commented 7 years ago

@nickhaw Are you getting the same kind of exceptions as @petronela0306 ?

Zhuinden commented 7 years ago

I wonder if this has anything to do with the "invalid lock file" exceptions.

ghost commented 7 years ago

@nickhaw mentioned it happened only on release builds, I missed that when I opened the issue. The same is for me, only with builds signed with the release keystore

nickhaw commented 7 years ago

@cmelchior Yes java.lang.IllegalArgumentException: Invalid query: table 'X' not found in this schema. After a little more investigation it looks likely to be something to do with ProGuard. When running the app as a release build directly from Android Studio it skips ProGuard obfuscation compiles and launches without crashing. However if I compile the same build with Proguard upload to Beta on Google Play and update the app this way it then crashes with the error above.

cmelchior commented 7 years ago

We found a bug in our Proguard setup that we fixed in 3.3.0 https://github.com/realm/realm-java/blob/master/CHANGELOG.md#330-2017-05-24 Can you try upgrading to 3.3.1 and see if it still crashes?

Zhuinden commented 7 years ago

@nickhaw that was a bug introduced in 3.2.0, and fixed in 3.3.0

nickhaw commented 7 years ago

@cmelchior @Zhuinden Thanks for your time. I can confirm the Realm version which is crashing is 3.2.1. Have now updated to 3.3.1 and all seems to be fine. Sorry for not picking up on this sooner. I don't always bump the Realm version with each update... lesson learned!

Zhuinden commented 7 years ago

@nickhaw well, Proguard configuration hadn't broken in a while either... it was a critical error so it was fixed rather quickly.

beeender commented 6 years ago

This issue doens't contain too much information (like backtrace), and i think this issue has been fixed already. Close it for now. If this issue is still happening with latest version, feel free to reopen it.