Retrofit 2 not sending data when ProGuard is enabled

前端 未结 7 1141
抹茶落季
抹茶落季 2020-12-30 00:43

I try to login my users using Retrofit 2. (Basically a GET to the login URL with a basic header) It works well but once I ProGuard it, the Header Authorization is not sent a

7条回答
  •  难免孤独
    2020-12-30 01:35

    I finally managed to make it work. Here is the proguard configuration regarding Retrofit 2

    # Retrofit
    -dontwarn retrofit2.**
    -dontwarn org.codehaus.mojo.**
    -keep class retrofit2.** { *; }
    -keepattributes Signature
    -keepattributes Exceptions
    -keepattributes *Annotation*
    
    -keepattributes RuntimeVisibleAnnotations
    -keepattributes RuntimeInvisibleAnnotations
    -keepattributes RuntimeVisibleParameterAnnotations
    -keepattributes RuntimeInvisibleParameterAnnotations
    
    -keepattributes EnclosingMethod
    
    -keepclasseswithmembers class * {
        @retrofit2.* ;
    }
    
    -keepclasseswithmembers interface * {
        @retrofit2.* ;
    }
    

    Thanks @xudshen

    UPDATE

    The main problem: I used proguard-android-optimize So I should added:

    -keepclasseswithmembers class * {
        @retrofit2.http.* ;
    }
    

    I also switched back to the regular Retrofit 2 proguard config provided by square :

    # Platform calls Class.forName on types which do not exist on Android to determine platform.
    -dontnote retrofit2.Platform
    # Platform used when running on RoboVM on iOS. Will not be used at runtime.
    -dontnote retrofit2.Platform$IOS$MainThreadExecutor
    # 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
    

提交回复
热议问题