When proguard is enabled, after an API call with retrofit, I recieve a list of LinkedHashMapTree that causes this error:
java.lang.ClassCastException: com.squareup.moshi.LinkedHashTreeMap cannot be cast to
...response.SearchItemResponse
with proguard disabled the crash doesn't happen and the list is of type List<SearchItemResponse> instead of List<LinkedHashTreeMap>
My proguard file:
-keepclassmembers public class * extends androidx.lifecycle.ViewModel { public <init>(...); }
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep, allowobfuscation,allowshrinking class com.squareup.moshi.JsonAdapter
Is there something I'm missing on the proguard rules?
The problem is resolved by using the @Keep annotation on the data class and it's sublcasses.
From the doc of @Keep:
Denotes that the annotated element should not be removed when the code is minified at build time. This is typically used on methods and classes that are accessed only via reflection so a compiler may think that the code is unused.