启用 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
我在混淆器规则中遗漏了什么吗?
最佳答案
通过在数据类及其子类上使用 @Keep 注释解决了该问题。
来自@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.
关于android - Moshi LinkedHashTreeMap 类使用 Proguard 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76782249/