2017-10-18 134 views
0

我想設置的ProGuard我的應用程序,我遇到了以下錯誤致命錯誤:將Proguard的到Retrofit2和GSONAdapters

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" 
+0

從build.gradle顯示您的依賴關係 – shmakova

回答

2

相關的依賴性通過在我的gradle這個最新版本GSON,我是能夠解決此錯誤: compile 'com.google.code.gson:gson:2.8.2'

這將是修復,直到任何庫使用舊版本(不可變或retrofit2)更新其gson。