Proguard no longer works with Retrofit

前端 未结 3 1485
萌比男神i
萌比男神i 2020-12-16 15:34

I have found older questions which touch on the same subject but with the latest versions none of the available answers work for me.

I am using Retrofit in my projec

3条回答
  •  眼角桃花
    2020-12-16 15:55

    This configuration worked for retrofit with gson.

    #Using for retrofit & gson
    -keep class com.google.gson.** { *; }
    -keep class com.google.inject.** { *; }
    -keep class org.apache.http.** { *; }
    -keep class org.apache.james.mime4j.* { *; }
    -keep class javax.inject.** { *; }
    -keep class retrofit.** { *; }
    -keep class sun.misc.Unsafe { *; }
    -keep class com.google.gson.stream.** { *; }
    -keepclassmembernames interface * {
        @retrofit.http.* ;
    }
    -keep interface retrofit.** { *;}
    -keep interface com.squareup.** { *; }
    -dontwarn rx.**
    -dontwarn retrofit.**
    

    plus you need to add all the POJO classes which is used with retrofit just like below.

    -keep class com.google.gson.examples.android.model.** { *; }
    -keep class com.packagename.your.pojo.models.** { *; }
    

    keepattributes like below

    -keepattributes Exceptions
    -keepattributes InnerClasses
    -keepattributes Signature
    -keepattributes Deprecated
    -keepattributes SourceFile
    -keepattributes LineNumberTable
    -keepattributes *Annotation*
    -keepattributes EnclosingMethod
    

    A nice discussion about proguard with retrofit goes here

提交回复
热议问题