【问题标题】:Fatal error applying Proguard to Retrofit2 and GSONAdapters将 Proguard 应用于 Retrofit2 和 GSONAdapters 的致命错误
【发布时间】:2018-03-30 19:13:22
【问题描述】:

我正在尝试在我的应用上设置 proguard,但遇到以下错误:

java.lang.NoSuchMethodError: No static method getParameterized(Ljava/lang/reflect/Type;[Ljava/lang/reflect/Type;)Lcom/google/gson/reflect/TypeToken; in class Lcom/google/gson/reflect/TypeToken; or its super classes (declaration of 'com.google.gson.reflect.TypeToken' appears in /data/app/com.rw.crm.leads-1/base.apk)
                                                                                    at com.rw.crm.leads.model.response.GsonAdaptersResponse$ListResponseTypeAdapter.<init>(GsonAdaptersResponse.java:185)
                                                                                    at com.rw.crm.leads.model.response.GsonAdaptersResponse.create(GsonAdaptersResponse.java:36)
                                                                                    at com.google.gson.Gson.getAdapter(Gson.java:423)

我无法提出解决此问题的 proguard 配置。这就是我现在在 gson proguard 文件中的内容:

# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**

#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.rw.crm.leads.model.** { *; }

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# To make the app compile
-dontwarn com.google.gson.reflect.TypeToken

# Why doesn't this work?
-keep class com.google.gson.reflect.** { *; }

编辑:这里是 build.gradle 的相关依赖项

compile "com.squareup.retrofit2:retrofit:2.3.0"
compile "com.squareup.retrofit2:converter-gson:2.3.0"

annotationProcessor "org.immutables:value:2.5.6"
provided "org.immutables:gson:2.5.6:annotations"

【问题讨论】:

  • 从 build.gradle 显示你的依赖

标签: android proguard retrofit2 immutables-library gson


【解决方案1】:

通过在我的 gradle 中包含最新的 gson 版本,我能够解决这个错误: compile 'com.google.code.gson:gson:2.8.2'

这将是修复,直到使用旧版本(不可变或改造 2)的任何库更新其 gson。

【讨论】:

    猜你喜欢
    • 2017-11-13
    • 1970-01-01
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    相关资源
    最近更新 更多