For now the progurad rules in http://square.github.io/retrofit/ won't work correctly if you are using proguard-android-optimize.
We need add this to make it work.
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
For more information please see http://stackoverflow.com/questions/35506111/retrofit-2-not-sending-data-when-proguard-is-enabled.
Your rule will prevent methods from being obfuscated which is unnecessary and also unused methods will be kept. This one should be more optimal:
-keepclassmembernames,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
It'll stop ProGuard from removing parameters but allow proper obfuscation and shrinking.
Nothing is working
Android Studio builded failed if adding following proguard options:
-keepclassmembernames,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
No modifier should be added following keepclassmembernames as the manual writes below:
https://www.guardsquare.com/en/proguard/manual/usage#keepclassmembernames
@HenryChao24 怎么解决 我也遇到了 这个链接404了
@joker-fu
It's a workaround below.
-keepclassmembers,allowshrinking,allowobfuscation interface * { @retrofit2.http.** <methods>; }
Fixed by c6a61b3307c6ef4627b722a37e23d2b5953a4420
Please use in this lines Dexguard-project.txt file. that's all. Enjoy your coding...
-keep class retrofit.* { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.
}
-keepclasseswithmembers interface * {
@retrofit2.http.*
}
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault
-dontobfuscate
-dontoptimize
-dontshrink
No. Those rules are crazy. You're much better off disabling Dexguard than using those rules.
Most helpful comment
Your rule will prevent methods from being obfuscated which is unnecessary and also unused methods will be kept. This one should be more optimal:
It'll stop ProGuard from removing parameters but allow proper obfuscation and shrinking.