I have a RealmModule in a library that has been working fine. I recently tried making a build with R8 enabled (enabled by default in 3.4) and it crashes on app start with:
Caused by: java.lang.IllegalArgumentException: com.myapp.ModelModule is not a RealmModule. Add @RealmModule to the class definition.
This is the class definition:
@RealmModule(library = true, allClasses = true)
internal class ModelModule : RealmModuleMarker
I checked the bytecode in the dexfile and the annotation has been stripped. This works fine with proguard.
RealmObject and RealmModel are fine.
I tried adding the following to my proguard rules (which I think the realm library includes anyways), but it didn't help:
-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep @interface io.realm.annotations.RealmModule
Realm version(s): 5.9.1
Realm Sync feature enabled: No
Android Studio version: 3.4.0 Beta 5
Android Build Tools version: Latest
Gradle version: 5.1.1
Which Android version and device(s): Pixel and Pixel 2 running 9
Figured it out. I needed:
-keep @interface io.realm.annotations.RealmModule { *; }
-keep class io.realm.annotations.RealmModule { *; }
Hey - looks like you forgot to add a T:* label - could you please add one?
Issue should not be closed. Confirmed. This is either a R8 bug or realm compat with latest build tools.
@bmunkholm @eygraber Please reopen this issue as it needs to be tracked.
I can confirm that migrating to Android Studio 3.4 with R8 enabled by default causes our app to crash. We're using the old version of realm-android-adapters though (io.realm:android-adapters:2.1.1).
As a work around, we're disabling R8 (project's gradle.properties)
android.enableR8 = false. Hope this helps someone else who might have this issue as well.
If you use Realm 5.x+ then you should use the Android adapters 3.0.0
If you use Realm 5.x+ then you should use the Android adapters 3.0.0
Ok thanks, will give it a try.
We are on the latest Realm and android-adapter release using AGP 3.4 with R8 and are also facing this issue. We used R8 before and it only occured with the latest version shipping with AS/AGP 3.4.
Should Realm ship its own R8 rules or is it a bug in R8?
Using @eygraber's ProGuard/R8 rules we got it working again without having to disable R8.
We are using Realm 5.5 and thanks to @eygraber's ProGuard/R8 rules it compiles, but fails upgrading.
It is weird because there is no error at all doing the schema upgrade process, but the upgraded database returns null for every new column.
Disabling R8 the upgrade goes flawlessly.
Edit: Still happens with Realm 5.10.0
Proguard test conf:
# R8 Configuration for Realm
-keep @interface io.realm.annotations.RealmModule { *; }
-keep class io.realm.annotations.RealmModule { *; }
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class *
-dontwarn javax.**
-keepnames public class * extends io.realm.RealmObject
-keep public class * extends io.realm.RealmObject { *; }
-keep class io.realm.** { *; }
Any updates on this issue? From Android studio 3.4.2 R8 is being used by default, so I think it is an important one to fix.
https://github.com/realm/realm-java/blob/master/CHANGELOG.md
This issue was fixed version 6.0.2 . So update it to latest version
Most helpful comment
Figured it out. I needed: