使用 proguard 将 kotlin 升级到 1.5.20 时,Moshi 1.12.0 反射失败

Moshi 1.12.0 reflection failed when upgrade kotlin to 1.5.20 with proguard

它在 kotlin 1.4.31 上运行良好。 升级kotlin到1.5.20后,打开APP一直闪退。 错误是

kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Unresolved class: class d.e.i.h.m$b
    at kotlin.reflect.jvm.internal.KClassImpl.reportUnresolvedClass(KClassImpl.kt:329)
    at kotlin.reflect.jvm.internal.KClassImpl.access$reportUnresolvedClass(KClassImpl.kt:44)
    at kotlin.reflect.jvm.internal.KClassImpl$Data$descriptor.invoke(KClassImpl.kt:56)
    at kotlin.reflect.jvm.internal.KClassImpl$Data$descriptor.invoke(KClassImpl.kt:47)
    at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(ReflectProperties.java:92)
    at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:31)
    at kotlin.reflect.jvm.internal.KClassImpl$Data.getDescriptor(Unknown Source:7)
    at kotlin.reflect.jvm.internal.KClassImpl.getDescriptor(KClassImpl.kt:182)
    at kotlin.reflect.jvm.internal.KClassImpl.isAbstract(KClassImpl.kt:271)
    at d.o.a.a0.a.b.a(KotlinJsonAdapter.kt:214)
    at d.o.a.u.f(Moshi.java:145)
    at d.o.a.u.e(Moshi.java:105)
    at d.o.a.u.d(Moshi.java:74)
    at d.o.a.e.m(CollectionJsonAdapter.java:54)
    at d.o.a.e$a.a(CollectionJsonAdapter.java:38)
    at d.o.a.u.f(Moshi.java:145)
    at d.o.a.a0.a.b.a(KotlinJsonAdapter.kt:262)
    at d.o.a.u.f(Moshi.java:145)
    at d.o.a.u.e(Moshi.java:105)
    at d.o.a.u.c(Moshi.java:79)
    at d.e.i.f.d.c(TimezoneUtils.kt:27)
    at com.xxx.xxx.MyApplication.onCreate(MyApplication.kt:33)

我尝试根据moshi更新混淆器github,但问题仍然存在。

# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

-keepclasseswithmembers class * {
    @com.squareup.moshi.* <methods>;
}

-keep @com.squareup.moshi.JsonQualifier @interface *

# Enum field names are used by the integrated EnumJsonAdapter.
# values() is synthesized by the Kotlin compiler and is used by EnumJsonAdapter indirectly
# Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi.
-keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum {
    <fields>;
    **[] values();
}

# Keep helper method to avoid R8 optimisation that would keep all Kotlin Metadata when unwanted
-keepclassmembers class com.squareup.moshi.internal.Util {
    private static java.lang.String getKotlinMetadataClassName();
}

有没有人有同样的问题或任何建议?

将 gradle 插件升级到 4.2.2 后。反射问题已修复。 (但在启用 proguard 时仍然无法解析 Retrofit2 响应。继续尝试..)