0

I just updated my Gradle to 3.4.1. I am having an API call inside one of my module. I am using the module inside the app :

implementation com.mindvalley.module_login:Module_Login:$rootConfiguration.loginLibraryVersion

Now when I generate a signed build with ProGuard, the object is null, meaning retrofit is not able to parse the object.

P.S. : This works fine with debug mode or if I run the app with Gradle version 3.3.2

My Retrofit Proguard file :

-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

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


-keepattributes Signature, InnerClasses, EnclosingMethod

-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

-dontwarn javax.annotation.**

-dontwarn kotlin.Unit

-dontwarn retrofit2.KotlinExtensions

-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>


-dontwarn org.codehaus.mojo.**
-keepattributes *Annotation*

-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations

-keepattributes EnclosingMethod

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

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

My OkHttp proguard file :

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

-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

-dontwarn org.codehaus.mojo.animal_sniffer.*

-dontwarn okhttp3.internal.platform.ConscryptPlatform

-dontwarn org.codehaus.mojo.animal_sniffer.*

My GSON proguard file :

-keepattributes Signature
-keepattributes EnclosingMethod

-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-dontwarn com.google.gson.internal.UnsafeAllocator

-keepattributes Signature

-keepattributes *Annotation*

-dontwarn sun.misc.**
-keep class com.google.gson.examples.android.model.** { <fields>; }

-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}
shizhen
  • 12,251
  • 9
  • 52
  • 88
Harsh
  • 599
  • 3
  • 20

1 Answers1

1

P.S. : This works fine with debug mode or if I run the app with Gradle version 3.3.2

Since, Gradle Plugin version 3.4.0, D8/R8 is enabled by default and obfuscation will be done by R8 instead of ProGuard.

See Stick to ProGuard Obfuscation for how to stick with Proguard.

See Android/java: Transition / Migration from ProGuard to R8? for how to migrate to R8.

shizhen
  • 12,251
  • 9
  • 52
  • 88
  • It works fine if I disable R8 in gradle.properties. With R8 enabled it fails. Can you please tell if we need to edit our ProGuard files or add something extra for R8? – Harsh May 28 '19 at 08:18