Kotlin / kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Apache License 2.0
5.43k stars 622 forks source link

Unable to run with Proguard Enable #1555

Closed mdhanif-simformsolutions closed 3 years ago

mdhanif-simformsolutions commented 3 years ago

Describe the bug I am having a KMM project in which I need to enable Proguard for my release mode. As soon as I enable isMinifyEnabled = true in my android module build.gradle file I get this error :- Serializer for class 'e' is not found. Mark the class as @Serializable or provide the serializer explicitly.

Now I already have gone through this issue and had the same Proguard rules applied in my project but I am still unable to solve this. To Reproduce Proguard Rules :-

-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.SerializationKt
-keep,includedescriptorclasses class <My Package Name>**$$serializer { *; } # <-- change package name to your app's
-keepclassmembers class <My Package Name>.** { # <-- change package name to your app's
    *** Companion;
}
-keepclasseswithmembers class <My Package Name>.** { # <-- change package name to your app's
    kotlinx.serialization.KSerializer serializer(...);
}

I don't get any crashes or any Logs in my logcat but I can see the error simply printing in my device which says :- Serializer for class 'e' is not found. Mark the class as @Serializable or provide the serializer explicitly.

I can even see my Model class print as it is.

Expected behavior App should work as it is while having minifyEnabled as true

Environment

mdhanif-simformsolutions commented 3 years ago

Issue has been resolved. the main problem was I needed to setup consumerProguardFiles in my shared module. As soon as I setup that this works perferctly.