Java 迁移到androidx后出现抽象方法错误
Logcat错误Java 迁移到androidx后出现抽象方法错误,java,android,gson,retrofit,androidx,Java,Android,Gson,Retrofit,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$1.read(SourceFile:199) at com.google.gson.internal
java.lang.AbstractMethodError: abstract method "java.lang.Object com.google.gson.TypeAdapter.read(com.google.gson.stream.JsonReader)"
at com.google.gson.TypeAdapter$1.read(SourceFile:199)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.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