启用 proguard 后,在使用改造的 API 调用后,我收到导致此错误的 LinkedHashMapTree 列表:
java.lang.ClassCastException: com.squareup.moshi.LinkedHashTreeMap cannot be cast to
...response.SearchItemResponse
禁用混淆器后,不会发生崩溃,并且列表的类型为 List
我的 proguard 文件:
-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
我在 proguard 规则中遗漏了什么吗?
通过在数据类及其子类上使用@Keep注释解决了该问题。
来自@Keep的文档:
表示在构建时缩小代码时不应删除带注释的元素。这通常用于仅通过反射访问的方法和类,因此编译器可能会认为该代码未使用。