Moshi LinkedHashTreeMap 类使用 Proguard 转换异常

问题描述 投票:0回答:1

启用 proguard 后,在使用改造的 API 调用后,我收到导致此错误的 LinkedHashMapTree 列表:

java.lang.ClassCastException: com.squareup.moshi.LinkedHashTreeMap cannot be cast to 
 ...response.SearchItemResponse

禁用混淆器后,不会发生崩溃,并且列表的类型为 List 而不是 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 规则中遗漏了什么吗?

android retrofit proguard moshi
1个回答
0
投票

通过在数据类及其子类上使用@Keep注释解决了该问题。

来自@Keep的文档:

表示在构建时缩小代码时不应删除带注释的元素。这通常用于仅通过反射访问的方法和类,因此编译器可能会认为该代码未使用。

© www.soinside.com 2019 - 2024. All rights reserved.