Retrofit2 proguard删除参数

我使用改进2和在我的项目中使用proguard

我的proguard:

-dontwarn retrofit2.** -keep class retrofit2.** { *; } -keepattributes Signature -keepattributes Exceptions -keepclassmembers class fqcn.of.javascript.interface.for.webview { public *; } # Begin twitter 4j. -dontwarn twitter4j.** -keep class twitter4j.conf.PropertyConfigurationFactory -keep class twitter4j.** { *; } # End twitter 4j. # Start androidsocialnetworks -keep class com.androidsocialnetworks.lib.** { *; } # End androidsocialnetworks. # Google api -keep class com.google.** { *;} -keep interface com.google.** { *;} -dontwarn com.google.** -dontwarn sun.misc.Unsafe -dontwarn com.google.common.collect.MinMaxPriorityQueue -keepattributes *Annotation*,Signature -keep class * extends com.google.api.client.json.GenericJson { *; } -keep class com.google.api.services.** { *; } -dontwarn com.google.android.gms.cast.** -dontwarn com.google.android.gms.** -keep class com.google.android.gms.** { *; } -keep class * extends java.util.ListResourceBundle { protected Object[][] getContents(); } -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { public static final *** NULL; } -keepnames @com.google.android.gms.common.annotation.KeepName class * -keepclassmembernames class * { @com.google.android.gms.common.annotation.KeepName *; } -keepnames class * implements android.os.Parcelable { public static final ** CREATOR; } # End google api # Other -optimizations !class/unboxing/enum -dontwarn com.google.code.** -dontwarn oauth.signpost.** -dontwarn javax.management.** -dontwarn javax.xml.** #-dontwarn org.apache.** #-dontwarn org.slf4j.** -keep class org.** { *; } -keep class javax.** { *; } -assumenosideeffects class * implements org.slf4j.Logger { public *** trace(...); public *** debug(...); public *** info(...); public *** warn(...); public *** error(...); } # Rx java -dontwarn sun.misc.** -keep class rx.internal.util.unsafe.** { *; } -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* { long producerIndex; long consumerIndex; } -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef { rx.internal.util.atomic.LinkedQueueNode producerNode; } -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef { rx.internal.util.atomic.LinkedQueueNode consumerNode; } # End other # Java mail -dontwarn java.awt.** -dontwarn java.beans.Beans -dontwarn javax.security.** -keep class javamail.** {*;} -keep class javax.mail.** {*;} -keep class javax.activation.** {*;} -keep class com.sun.mail.dsn.** {*;} -keep class com.sun.mail.handlers.** {*;} -keep class com.sun.mail.smtp.** {*;} -keep class com.sun.mail.util.** {*;} -keep class mailcap.** {*;} -keep class mimetypes.** {*;} -keep class myjava.awt.datatransfer.** {*;} -keep class org.apache.harmony.awt.** {*;} -keep class org.apache.harmony.misc.** {*;} # End java mail 

而在build.gradle我也使用一些proguard文件:(我从: https : //github.com/krschultz/android-proguard-snippets )

  proguardFile 'proguards/proguard-support-v7-appcompat.pro' proguardFile 'proguards/proguard-google-play-services.pro' proguardFile 'proguards/proguard-gson.pro' proguardFile 'proguards/proguard-butterknife-7.pro' proguardFile 'proguards/proguard-square-retrofit2.pro' proguardFile 'proguards/proguard-rx-java.pro' proguardFile 'proguards/proguard-rxjava-promises.pro' proguardFile 'proguards/proguard-square-okhttp3.pro' proguardFile 'proguards/proguard-jsoup.pro' proguardFile 'proguards/proguard-jackson-2.pro' proguardFile 'proguards/proguard-simple-xml.pro' proguardFile 'proguards/proguard-support-design.pro' proguardFile 'proguards/proguard-square-okio.pro' proguardFile 'proguards/proguard-facebook.pro' 

这里是一个定义API的方法:

 @GET("app/authenticate") Observable<AuthenticationModel> authenticate( @Query("email") String email, @Query("password") String password ); 

然后后proguard我反编译APK文件,然后我得到:

 @GET("app/authenticate") rx.a<AuthenticationModel> a(); 

我不知道为什么所有的参数被删除。 (注意:当前项目工作以及如果不使用proguard)请帮助!

UPDATE

主要问题:我用proguard-android-optimize所以我应该添加(作为@EpicPandaForce答案):

 -keepclasseswithmembers class * { @retrofit2.http.* <methods>; } 

  • Retofit2错误java.io.EOFException:行1列1的input结束
  • 如何在Retrofit 2中上传图像文件
  • 如何从Retrofit2获取字符串响应?
  • 改造 - 多部分请求:必需的MultipartFile参数'file'不存在
  • Retrofit 2不能上传带有两个额外单独string参数的文件
  • Retrofit和RxJava:如何结合两个请求并获得两个结果?
  • IllegalArgumentException:找不到rx.Observable RxJava调用适配器,Retrofit2
  • 如何进行多个请求,并等待数据来自2.0中的所有请求 - android
  • 尝试以下规则

     -keepclasseswithmembers class * { @retrofit2.http.* <methods>; } 

    可能需要使用Retrofit2来调整软件包。

    从改造文档,我们应该添加下面列出的行到proguard文件:

     #Retrofit # Platform calls Class.forName on types which do not exist on Android to determine platform. -dontnote retrofit2.Platform # Platform used when running on Java 8 VMs. Will not be used at runtime. -dontwarn retrofit2.Platform$Java8 # Retain generic type information for use by reflection by converters and adapters. -keepattributes Signature # Retain declared checked exceptions for use by a Proxy instance. -keepattributes Exceptions 

    但根据我的经验,我们也应该添加这些线

     -keep class retrofit.** { *; } -keepattributes Signature -keepattributes Exceptions -keepclasseswithmembers class * { @retrofit2.http.* <methods>; } -keepclasseswithmembers interface * { @retrofit2.http.* <methods>; } 

    我们还需要保留改造使用的Model类:

     -keep public class your.package.to.models.** {*;}