realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
946 stars 57 forks source link

IllegalStateException after obfuscation #778

Closed tarasmorskyi-mediamonks closed 2 years ago

tarasmorskyi-mediamonks commented 2 years ago

Receiving ISE on creation of RealmConfiguration on release build which got obfuscated with Dexguard. Error message:

Caused by: java.lang.IllegalStateException: Couldn't find companion object of class 'ProductEntity'.
2022-04-06 10:55:01.901 32219-32219/? E/AndroidRuntime: A common cause for this is when the `io.realm.kotlin` is not applied to the Gradle module that contains the 'ProductEntity' class.Added these rules for RealmObject classes which didn't help:
-keep,includedescriptorclasses class com.projectname.data.vo.**$$serializer { *; }
-keepclassmembers class com.projectname.data.vo.** { *** Companion; }
-keepclasseswithmembers class com.projectname.data.vo.** {
    kotlinx.serialization.KSerializer serializer(...);
}

Is there any additional configuration needed for it? Or is it rather general misconfiguration of Dexguard on my side? Any kind of these issues are not happening on pre-KMM version of project.

nhachicha commented 2 years ago

Hi @tarasmorskyi-mediamonks have you tried the Proguard conf specified here https://github.com/realm/realm-kotlin-samples/blob/main/Bookshelf/androidApp/proguard-rules.pro ?

tarasmorskyi-mediamonks commented 2 years ago

Hi @nhachicha, how are these rules different to what I've shared above? There are only first few lines extra which are Kotlin Serialisation specific which I had already but didn't mention here as RealmObjects are not annotated as Serialisable

nhachicha commented 2 years ago

@tarasmorskyi-mediamonks can you please share more on your project to try to reproduce it:

tarasmorskyi-mediamonks commented 2 years ago

Kotlin 1.6.10 Realm Kotlin 0.10.2 It's a company project, so I cannot share access to repo It happens to any model, even as simple as this one:

open class SearchedProduct : RealmObject {

    @PrimaryKey
    var id: Long = SearchedProductId

    var productId: RealmList<String> = realmListOf()
    var updateTime: Long = 0
}

What part of Gradle configuration are you interested in?

nhachicha commented 2 years ago
tarasmorskyi-mediamonks commented 2 years ago
nhachicha commented 2 years ago

@tarasmorskyi-mediamonks hmm https://github.com/realm/realm-kotlin-samples/tree/main/Bookshelf checks all the boxes (uses ProGaurd, model in multiplatform module and same Proguard rules ...) I wonder if you can manage to reproduce the issue using the Bookshelf as a starting base (i.e copy your model from the production app into it for instance) ?

tarasmorskyi-mediamonks commented 2 years ago

In the end issue was not with Proguard/Dexguard. It got fixed after updating gradle plugin from 7.0.4 to 7.1.2. Cannot understand why it didn't affect the debug build though.