iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🏆

Upgraded Realm from v4 to 10

に公開
2024/12/26

My "biggest challenge of the year" in 2024 was upgrading a certain Android app from Realm v4 to 10.

This upgrade eventually resulted in a difference of about 9,000 lines.

To be precise, the version of Realm in this app was v4.2.0, which was released on November 17, 2017.

https://github.com/realm/realm-java/releases/tag/v4.2.0

Earlier this year, I was organizing dependencies in preparation for the annual summer Android API level update. To update the app after August 31, it was necessary to target API Level 34.

Starting August 31 2024:

  • New apps and app updates must target Android 14 (API level 34) to be submitted to Google Play

https://support.google.com/googleplay/android-developer/answer/11926878

The minimum AGP version for API Level 34 is 8.1.1.

https://developer.android.com/studio/releases#api-level-support

The app in question was using Gradle 7.4.0, and to update to version 8.x, it was necessary to update Realm to 10.15.1.

This should be fixed with 10.15.1 which was just released. update your realm classpath in build.gradle to be :

https://stackoverflow.com/questions/76026649/build-failed-in-agp-8-0-failed-to-apply-plugin-realm-android-api-android-re

Upgrading Realm to v10 all at once made it difficult to isolate problems, so I organized the issues while upgrading incrementally. I struggled with build errors caused by several dependent libraries—possibly because of the Gradle upgrade causing cache issues rather than Realm itself. I'll omit the details in this article.

Dependent libraries
  • For libraries that depend on JCenter, I made a temporary fix to fetch them from JCenter. Since those libraries are no longer maintained, they didn't seem to be distributed anywhere else.
  • For libraries causing unexplained build errors, after a careful check, I realized they weren't being used in the first place, so I removed them to avoid the errors.

Once the Realm-related issues were organized, the changes were straightforward.

- realm.findAllSorted("column_name")
+ realm.sort("column_name").findAll()
- realm.findAllSorted("column_name").first(null)
+ realm.sort("column_name").findFirst()
- realm.distinct("column_name")
+ realm.distinct("column_name").findAll()

There were also many Realm write violations on the UI thread. I gave up on addressing them all at once and instead allowed them temporarily to handle them incrementally.

allowWritesOnUiThread(true)

As a result, although the project originally had a mix of Java 8 and 11, I unified it to Java 17, and the API level now meets the requirements, allowing for app updates from this summer onwards.

Initially, when I changed Realm from v4 to 10, there were nearly 300 errors, and I almost felt like giving up, thinking it was impossible. By isolating the problems and choosing an incremental approach instead of trying to solve everything at once, I somehow managed to make it in time for the summer update. This became my biggest challenge of the year.

The update to Realm v10 had been tracked as an issue in this project since October 2020, and it was finally closed after about four years.

GitHubで編集を提案

Discussion