Retrofit 2.4.0 with proguard

Ahmed Isa :

When I add Retrofit 2.4.0 library to android project >

implementation 'com.squareup.retrofit2:retrofit:2.4.0'

and set minifyEnabled {true}

buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }

and then add these rules to proguard-rules.pro

-keep class com.squareup.** { *; }
-keep interface com.squareup.** { *; }
-keep class retrofit2.** { *; }
-keep interface retrofit2.** { *;}
-keep interface com.squareup.** { *; }


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


-dontwarn rx.**
-dontwarn retrofit2.**
-dontwarn okhttp3.**
-dontwarn okio.**

Finally built and generated signed apk successfully but the issue is when run the ( release apk) > Retrofit requests not send and return { null } .. Whats the solution Please!

amin mahmoudi :

maybe because of other library work with retrofit like your downloader or parser.

important notice :

add rule to keep your model classes and subjects that work with parser like :

-keep class com.address_package.** { *; }

if you use okhttp or Okhttp3 with retrofit added below rules

note :and check your parser proguard rules too

LIBRARY: OkHttp

-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }

-dontwarn com.squareup.okhttp.**
-dontwarn okio.**

okhttp3

-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }

-dontwarn okhttp3.**

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=441466&siteId=1