迁移到androidx后抽象方法报错

Abstract method error after migrating to androidx

Logcat错误

java.lang.AbstractMethodError: abstract method "java.lang.Object com.google.gson.TypeAdapter.read(com.google.gson.stream.JsonReader)"
        at com.google.gson.TypeAdapter.read(SourceFile:199)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.read(SourceFile:131)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(SourceFile:222)
        at com.google.gson.Gson.fromJson(SourceFile:927)
        at com.google.gson.Gson.fromJson(SourceFile:892)
        at com.google.gson.Gson.fromJson(SourceFile:841)
        at com.google.gson.Gson.fromJson(SourceFile:813)
        

我用过的一些可能相关的库

implementation 'com.google.android.gms:play-services-location:17.1.0'
implementation "com.google.android.gms:play-services-gcm:17.0.0"
implementation "com.google.android.gms:play-services-auth:18.1.0"
implementation "com.google.android.gms:play-services-analytics:17.0.0"
implementation("com.google.guava:guava:30.0-android")
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.9.0"
implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
implementation 'com.google.firebase:firebase-analytics:18.0.0'

这是导致错误的代码行

test.add(gson.fromJson(arr.getJSONObject(i).toString(), Test.class));

迁移到 androidx 后出现此错误。 库已更新。

我能够通过更新 ProGuard 规则解决问题。

添加了以下内容。

-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer