From f81d5291d94d224f31d1b1179457395502ceda12 Mon Sep 17 00:00:00 2001 From: Dinar Khakimov <85668474+mdrlzy@users.noreply.github.com> Date: Mon, 21 Oct 2024 00:00:08 +0500 Subject: [PATCH] Enable proguard (#126) * Enable proguard * do not remove unused resources due to corrupted/missing currency icons * fix GroupCreateDialog cancel icon --- app/build.gradle.kts | 12 ++++--- app/proguard-rules.pro | 36 ++++++++++++++++++- .../data/network/dto/CryptoRateResponse.kt | 3 ++ .../rate/data/network/dto/FiatRateResponse.kt | 3 ++ .../rate/presentation/ui/GroupCreateDialog.kt | 2 +- 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c7175bd2b..08a7394e8 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -49,12 +49,14 @@ android { ), ) } + release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro", - ) + postprocessing { + isRemoveUnusedCode = true + isObfuscate = false + isOptimizeCode = true + proguardFiles("proguard-rules.pro") + } signingConfig = signingConfigs.getByName("testRelease") addManifestPlaceholders( diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 481bb4348..8ad9fff0c 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -18,4 +18,38 @@ # 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 + +##---------------Begin: proguard configuration for Gson ---------- +# https://github.com/google/gson/blob/main/examples/android-proguard-example/proguard.cfg +# Gson uses generic type information stored in a class file when working with fields. Proguard +# removes such information by default, so configure it to keep all of it. +-keepattributes Signature + +# For using GSON @Expose annotation +-keepattributes *Annotation* + +# Gson specific classes +-dontwarn sun.misc.** +#-keep class com.google.gson.stream.** { *; } + +# Application classes that will be serialized/deserialized over Gson +-keep class com.google.gson.examples.android.model.** { ; } + +# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory, +# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter) +-keep class * extends com.google.gson.TypeAdapter +-keep class * implements com.google.gson.TypeAdapterFactory +-keep class * implements com.google.gson.JsonSerializer +-keep class * implements com.google.gson.JsonDeserializer + +# Prevent R8 from leaving Data object members always null +-keepclassmembers,allowobfuscation class * { + @com.google.gson.annotations.SerializedName ; +} + +# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher. +-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken +-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken + +##---------------End: proguard configuration for Gson ---------- diff --git a/app/src/main/java/dev/arkbuilders/rate/data/network/dto/CryptoRateResponse.kt b/app/src/main/java/dev/arkbuilders/rate/data/network/dto/CryptoRateResponse.kt index 9038b3ea8..b5bd628be 100644 --- a/app/src/main/java/dev/arkbuilders/rate/data/network/dto/CryptoRateResponse.kt +++ b/app/src/main/java/dev/arkbuilders/rate/data/network/dto/CryptoRateResponse.kt @@ -1,5 +1,8 @@ package dev.arkbuilders.rate.data.network.dto +import androidx.annotation.Keep + +@Keep data class CryptoRateResponse( val symbol: String, val current_price: Double, diff --git a/app/src/main/java/dev/arkbuilders/rate/data/network/dto/FiatRateResponse.kt b/app/src/main/java/dev/arkbuilders/rate/data/network/dto/FiatRateResponse.kt index 58dc2d17a..86aa05d8f 100644 --- a/app/src/main/java/dev/arkbuilders/rate/data/network/dto/FiatRateResponse.kt +++ b/app/src/main/java/dev/arkbuilders/rate/data/network/dto/FiatRateResponse.kt @@ -1,5 +1,8 @@ package dev.arkbuilders.rate.data.network.dto +import androidx.annotation.Keep + +@Keep data class FiatRateResponse( val timestamp: Long, val rates: Map, diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/ui/GroupCreateDialog.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/GroupCreateDialog.kt index 034cafcc8..885227264 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/ui/GroupCreateDialog.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/GroupCreateDialog.kt @@ -76,7 +76,7 @@ fun GroupCreateDialogContent( Modifier .padding(end = 12.dp, top = 12.dp) .align(Alignment.TopEnd), - onClick = {}, + onClick = { onDismiss() }, ) { Icon( modifier = Modifier,