From ef279ce56569516348d5823394fd043e2460427d Mon Sep 17 00:00:00 2001 From: Yurii Surzhykov Date: Tue, 28 May 2024 14:31:32 -0700 Subject: [PATCH] Fix release build proguard rules Signed-off-by: Yurii Surzhykov --- app/build.gradle.kts | 3 +- app/proguard-rules.pro | 6 +++- app/retrofit2.pro | 48 ++++++++++++++++++++++++++ location-data/cache/consumer-rules.pro | 2 ++ location-data/cloud/build.gradle.kts | 2 +- location-data/cloud/consumer-rules.pro | 2 ++ location-data/cloud/retrofit2.pro | 48 ++++++++++++++++++++++++++ 7 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 app/retrofit2.pro create mode 100644 location-data/cloud/retrofit2.pro diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c098a48..af25b26 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -53,7 +53,8 @@ android { signingConfig = signingConfigs.getByName("release") proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" + "proguard-rules.pro", + "retrofit2.pro" ) } } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 481bb43..9e18db6 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -18,4 +18,8 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile + +-keep public class com.github.yuriisurzhykov.purs.data.cache.model.* +-keep public class com.github.yuriisurzhykov.purs.data.cloud.model.LocationCloud$Base +-keep public class com.github.yuriisurzhykov.purs.data.cloud.model.WorkingHourCloud$Base \ No newline at end of file diff --git a/app/retrofit2.pro b/app/retrofit2.pro new file mode 100644 index 0000000..6c1daaf --- /dev/null +++ b/app/retrofit2.pro @@ -0,0 +1,48 @@ +# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and +# EnclosingMethod is required to use InnerClasses. +-keepattributes Signature, InnerClasses, EnclosingMethod + +# Retrofit does reflection on method and parameter annotations. +-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations + +# Keep annotation default values (e.g., retrofit2.http.Field.encoded). +-keepattributes AnnotationDefault + +# Retain service method parameters when optimizing. +-keepclassmembers,allowshrinking,allowobfuscation interface * { + @retrofit2.http.* ; +} + +# Ignore annotation used for build tooling. +-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement + +# Ignore JSR 305 annotations for embedding nullability information. +-dontwarn javax.annotation.** + +# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath. +-dontwarn kotlin.Unit + +# Top-level functions that can only be used by Kotlin. +-dontwarn retrofit2.KotlinExtensions +-dontwarn retrofit2.KotlinExtensions$* + +# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy +# and replaces all potential values with null. Explicitly keeping the interfaces prevents this. +-if interface * { @retrofit2.http.* ; } +-keep,allowobfuscation interface <1> + +# Keep inherited services. +-if interface * { @retrofit2.http.* ; } +-keep,allowobfuscation interface * extends <1> + +# With R8 full mode generic signatures are stripped for classes that are not +# kept. Suspend functions are wrapped in continuations where the type argument +# is used. +-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation + +# R8 full mode strips generic signatures from return types if not kept. +-if interface * { @retrofit2.http.* public *** *(...); } +-keep,allowoptimization,allowshrinking,allowobfuscation class <3> + +# With R8 full mode generic signatures are stripped for classes that are not kept. +-keep,allowobfuscation,allowshrinking class retrofit2.Response \ No newline at end of file diff --git a/location-data/cache/consumer-rules.pro b/location-data/cache/consumer-rules.pro index e69de29..121cc59 100644 --- a/location-data/cache/consumer-rules.pro +++ b/location-data/cache/consumer-rules.pro @@ -0,0 +1,2 @@ +-keep public class kotlin.Result { *; } +-keep public class com.github.yuriisurzhykov.purs.data.cache.model.* \ No newline at end of file diff --git a/location-data/cloud/build.gradle.kts b/location-data/cloud/build.gradle.kts index 0be6ffd..f7f6f72 100644 --- a/location-data/cloud/build.gradle.kts +++ b/location-data/cloud/build.gradle.kts @@ -12,7 +12,7 @@ android { minSdk = ProjectProperties.minSdkVersion testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") + consumerProguardFiles("consumer-rules.pro", "retrofit2.pro") } buildTypes { diff --git a/location-data/cloud/consumer-rules.pro b/location-data/cloud/consumer-rules.pro index e69de29..2589ec5 100644 --- a/location-data/cloud/consumer-rules.pro +++ b/location-data/cloud/consumer-rules.pro @@ -0,0 +1,2 @@ +-keep public class com.github.yuriisurzhykov.purs.data.cloud.model.* +-keep public class kotlin.Result { *; } \ No newline at end of file diff --git a/location-data/cloud/retrofit2.pro b/location-data/cloud/retrofit2.pro new file mode 100644 index 0000000..6c1daaf --- /dev/null +++ b/location-data/cloud/retrofit2.pro @@ -0,0 +1,48 @@ +# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and +# EnclosingMethod is required to use InnerClasses. +-keepattributes Signature, InnerClasses, EnclosingMethod + +# Retrofit does reflection on method and parameter annotations. +-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations + +# Keep annotation default values (e.g., retrofit2.http.Field.encoded). +-keepattributes AnnotationDefault + +# Retain service method parameters when optimizing. +-keepclassmembers,allowshrinking,allowobfuscation interface * { + @retrofit2.http.* ; +} + +# Ignore annotation used for build tooling. +-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement + +# Ignore JSR 305 annotations for embedding nullability information. +-dontwarn javax.annotation.** + +# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath. +-dontwarn kotlin.Unit + +# Top-level functions that can only be used by Kotlin. +-dontwarn retrofit2.KotlinExtensions +-dontwarn retrofit2.KotlinExtensions$* + +# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy +# and replaces all potential values with null. Explicitly keeping the interfaces prevents this. +-if interface * { @retrofit2.http.* ; } +-keep,allowobfuscation interface <1> + +# Keep inherited services. +-if interface * { @retrofit2.http.* ; } +-keep,allowobfuscation interface * extends <1> + +# With R8 full mode generic signatures are stripped for classes that are not +# kept. Suspend functions are wrapped in continuations where the type argument +# is used. +-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation + +# R8 full mode strips generic signatures from return types if not kept. +-if interface * { @retrofit2.http.* public *** *(...); } +-keep,allowoptimization,allowshrinking,allowobfuscation class <3> + +# With R8 full mode generic signatures are stripped for classes that are not kept. +-keep,allowobfuscation,allowshrinking class retrofit2.Response \ No newline at end of file