From b93036281c6eb15121f204e3699e0940e67727c2 Mon Sep 17 00:00:00 2001 From: andresmr Date: Thu, 28 Nov 2024 12:06:16 +0100 Subject: [PATCH] build: Add proguard to library modules Signed-off-by: andresmr --- app/build.gradle.kts | 3 +- app/proguard-rules.pro | 20 ++++++ commons/build.gradle.kts | 2 +- commons/proguard-rules.pro | 12 +++- compose-table/build.gradle.kts | 2 +- compose-table/proguard-rules.pro | 15 +++- dhis2-mobile-program-rules/build.gradle.kts | 2 +- dhis2-mobile-program-rules/proguard-rules.pro | 4 +- dhis2_android_maps/build.gradle.kts | 2 +- dhis2_android_maps/proguard-rules.pro | 7 +- dhis_android_analytics/build.gradle.kts | 2 +- dhis_android_analytics/proguard-rules.pro | 15 +++- form/build.gradle.kts | 2 +- form/proguard-rules.pro | 6 +- stock-usecase/build.gradle.kts | 2 +- stock-usecase/proguard-rules.pro | 71 ++++++++++++++++++- tracker/build.gradle.kts | 2 +- tracker/proguard-rules.pro | 4 +- ui-components/build.gradle.kts | 6 +- ui-components/proguard-rules.pro | 4 +- viewpagerdotsindicator/build.gradle.kts | 4 +- 21 files changed, 154 insertions(+), 33 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 843fb3b0b9..699d634f47 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,4 @@ import com.android.build.api.variant.impl.VariantOutputImpl -import com.android.build.gradle.internal.scope.ProjectInfo.Companion.getBaseName import org.jetbrains.kotlin.gradle.dsl.JvmTarget import java.io.ByteArrayOutputStream import java.text.SimpleDateFormat @@ -146,7 +145,7 @@ android { isShrinkResources = true isMinifyEnabled = true proguardFiles( - getDefaultProguardFile("proguard-android.txt"), + getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) signingConfig = signingConfigs.getByName("release") diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 8d47cdffc6..9269e0b35e 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -24,6 +24,26 @@ # hide the original source file name. -renamesourcefileattribute SourceFile +# Keep Hilt-generated components and entry points +-keep class dagger.** { *; } +-keep class hilt.** { *; } +-keep class dagger.hilt.** { *; } +-keep class androidx.hilt.** { *; } +-keep class javax.inject.** { *; } +-keep class dagger.internal.** { *; } +-keep class dagger.multibindings.** { *; } +-keep interface dagger.hilt.EntryPoint +-keep interface dagger.hilt.InstallIn +-keep @dagger.hilt.components.SingletonComponent class * +# Keep DataBinding classes +-keep class androidx.databinding.** { *; } +-keep class **.databinding.** { *; } + +# Keep @Provides, @Binds, and other annotations +-keepattributes *Annotation* +-keepattributes InnerClasses +-keepattributes EnclosingMethod + -dontwarn autovalue.shaded.com.google$.errorprone.annotations.$CanIgnoreReturnValue -dontwarn autovalue.shaded.com.google$.errorprone.annotations.concurrent.$LazyInit -dontwarn com.android.org.conscrypt.SSLParametersImpl diff --git a/commons/build.gradle.kts b/commons/build.gradle.kts index 95de51b8b8..968e3c4140 100644 --- a/commons/build.gradle.kts +++ b/commons/build.gradle.kts @@ -31,7 +31,7 @@ android { getByName("debug") { } getByName("release") { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/commons/proguard-rules.pro b/commons/proguard-rules.pro index ff59496d81..42a4d1d22a 100644 --- a/commons/proguard-rules.pro +++ b/commons/proguard-rules.pro @@ -14,8 +14,16 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable # 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 ResourceManager +-keep class org.dhis2.commons.resources.ResourceManager { *; } + +# Keep DispatcherProvider +-keep class org.dhis2.commons.viewmodel.DispatcherProvider { *; } + +-dontwarn java.lang.invoke.StringConcatFactory \ No newline at end of file diff --git a/compose-table/build.gradle.kts b/compose-table/build.gradle.kts index af83802cbc..9ac7e62b14 100644 --- a/compose-table/build.gradle.kts +++ b/compose-table/build.gradle.kts @@ -24,7 +24,7 @@ android { getByName("debug") { } getByName("release") { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/compose-table/proguard-rules.pro b/compose-table/proguard-rules.pro index ff59496d81..c749d57e67 100644 --- a/compose-table/proguard-rules.pro +++ b/compose-table/proguard-rules.pro @@ -14,8 +14,19 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable # 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 KeyboardInputType and its nested classes +-keep class org.dhis2.composetable.model.KeyboardInputType { *; } +-keep class org.dhis2.composetable.model.KeyboardInputType$* { *; } + +# Keep ValidationResult and its nested classes +-keep class org.dhis2.composetable.model.ValidationResult { *; } +-keep class org.dhis2.composetable.model.ValidationResult$* { *; } + +-dontwarn java.lang.invoke.StringConcatFactory \ No newline at end of file diff --git a/dhis2-mobile-program-rules/build.gradle.kts b/dhis2-mobile-program-rules/build.gradle.kts index 6eeb1ae0ad..ce14d8399b 100644 --- a/dhis2-mobile-program-rules/build.gradle.kts +++ b/dhis2-mobile-program-rules/build.gradle.kts @@ -20,7 +20,7 @@ android { buildTypes { release { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/dhis2-mobile-program-rules/proguard-rules.pro b/dhis2-mobile-program-rules/proguard-rules.pro index 481bb43481..8a0dc3d157 100644 --- a/dhis2-mobile-program-rules/proguard-rules.pro +++ b/dhis2-mobile-program-rules/proguard-rules.pro @@ -14,8 +14,8 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable # 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 \ No newline at end of file diff --git a/dhis2_android_maps/build.gradle.kts b/dhis2_android_maps/build.gradle.kts index b14bcbe293..8333aa3291 100644 --- a/dhis2_android_maps/build.gradle.kts +++ b/dhis2_android_maps/build.gradle.kts @@ -25,7 +25,7 @@ android { getByName("debug") { } getByName("release") { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/dhis2_android_maps/proguard-rules.pro b/dhis2_android_maps/proguard-rules.pro index ff59496d81..7a378598f0 100644 --- a/dhis2_android_maps/proguard-rules.pro +++ b/dhis2_android_maps/proguard-rules.pro @@ -14,8 +14,11 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable # 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 + +-dontwarn org.dhis2.commons.bindings.BindingsKt +-dontwarn org.dhis2.commons.data.ProgramEventViewModel \ No newline at end of file diff --git a/dhis_android_analytics/build.gradle.kts b/dhis_android_analytics/build.gradle.kts index 409a55a178..4997ddd314 100644 --- a/dhis_android_analytics/build.gradle.kts +++ b/dhis_android_analytics/build.gradle.kts @@ -30,7 +30,7 @@ android { getByName("debug") { } getByName("release") { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/dhis_android_analytics/proguard-rules.pro b/dhis_android_analytics/proguard-rules.pro index ff59496d81..2781604428 100644 --- a/dhis_android_analytics/proguard-rules.pro +++ b/dhis_android_analytics/proguard-rules.pro @@ -14,8 +14,19 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable # 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 dhis2.org.analytics.charts.Charts +-keep class dhis2.org.analytics.charts.Charts { *; } + +# Preserve attributes related to DataBinding +-keepattributes *Annotation* + +-dontwarn org.dhis2.commons.bindings.CommonExtensionsKt +-dontwarn org.dhis2.commons.filters.data.FilterBindingsKt +-dontwarn org.dhis2.commons.resources.ColorType +-dontwarn org.dhis2.commons.resources.ColorUtils diff --git a/form/build.gradle.kts b/form/build.gradle.kts index ee311504b1..d5ec7d7a4a 100644 --- a/form/build.gradle.kts +++ b/form/build.gradle.kts @@ -29,7 +29,7 @@ android { getByName("debug") { } getByName("release") { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/form/proguard-rules.pro b/form/proguard-rules.pro index ff59496d81..0ea8d6a920 100644 --- a/form/proguard-rules.pro +++ b/form/proguard-rules.pro @@ -14,8 +14,10 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable # 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 + +-dontwarn java.lang.invoke.StringConcatFactory \ No newline at end of file diff --git a/stock-usecase/build.gradle.kts b/stock-usecase/build.gradle.kts index 3997b319a0..b8b9c485cf 100644 --- a/stock-usecase/build.gradle.kts +++ b/stock-usecase/build.gradle.kts @@ -40,7 +40,7 @@ android { buildTypes { getByName("release") { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/stock-usecase/proguard-rules.pro b/stock-usecase/proguard-rules.pro index ff59496d81..cecd169152 100644 --- a/stock-usecase/proguard-rules.pro +++ b/stock-usecase/proguard-rules.pro @@ -14,8 +14,75 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable # 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 Hilt-generated components and entry points +-keep class dagger.** { *; } +-keep class hilt.** { *; } +-keep class dagger.hilt.** { *; } +-keep class androidx.hilt.** { *; } +-keep class javax.inject.** { *; } +-keep class dagger.internal.** { *; } +-keep class dagger.multibindings.** { *; } +-keep interface dagger.hilt.EntryPoint +-keep interface dagger.hilt.InstallIn +-keep @dagger.hilt.components.SingletonComponent class * + +# Keep runtime annotations for Hilt and Dagger +-keepattributes *Annotation* + +# Keep ViewModels to ensure Hilt can reference them +-keep class org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel { *; } +-keep class org.dhis2.android.rtsm.ui.home.HomeViewModel { *; } +-keep class org.dhis2.android.rtsm.ui.base.BaseViewModel { *; } +-keep class org.dhis2.android.rtsm.services.SpeechRecognitionManager { *; } +-keep class org.dhis2.android.rtsm.services.rules.RuleValidationHelper { *; } +-keep class org.dhis2.android.rtsm.services.StockManager { *; } +-keep class org.dhis2.android.rtsm.services.MetadataManager { *; } +-keep class org.dhis2.android.rtsm.services.scheduler.BaseSchedulerProvider { *; } +-keep class org.dhis2.android.rtsm.services.StockTableDimensionStore { *; } +-keep class org.dhis2.android.rtsm.ui.managestock.TableModelMapper { *; } + +-dontwarn dhis2.org.analytics.charts.ui.GroupAnalyticsFragment$Companion +-dontwarn dhis2.org.analytics.charts.ui.GroupAnalyticsFragment +-dontwarn java.lang.invoke.StringConcatFactory +-dontwarn org.dhis2.commons.filters.FilterManager +-dontwarn org.dhis2.commons.orgunitselector.OUTreeFragment$Builder +-dontwarn org.dhis2.commons.orgunitselector.OUTreeFragment +-dontwarn org.dhis2.commons.orgunitselector.OrgUnitSelectorScope$ProgramCaptureScope +-dontwarn org.dhis2.commons.orgunitselector.OrgUnitSelectorScope +-dontwarn org.dhis2.commons.sync.OnDismissListener +-dontwarn org.dhis2.commons.sync.OnNoConnectionListener +-dontwarn org.dhis2.commons.sync.OnSyncNavigationListener +-dontwarn org.dhis2.commons.sync.SyncContext$TrackerProgram +-dontwarn org.dhis2.commons.sync.SyncContext +-dontwarn org.dhis2.commons.sync.SyncDialog +-dontwarn org.dhis2.composetable.TableConfigurationState +-dontwarn org.dhis2.composetable.TableScreenState +-dontwarn org.dhis2.composetable.TableState +-dontwarn org.dhis2.composetable.actions.TableResizeActions +-dontwarn org.dhis2.composetable.actions.Validator +-dontwarn org.dhis2.composetable.model.TableCell +-dontwarn org.dhis2.composetable.model.TextInputModel +-dontwarn org.dhis2.composetable.ui.DataSetTableScreenKt +-dontwarn org.dhis2.composetable.ui.TableColors +-dontwarn org.dhis2.composetable.ui.TableConfiguration +-dontwarn org.dhis2.composetable.ui.TableDimensions +-dontwarn org.dhis2.composetable.ui.TableThemeKt +-dontwarn org.dhis2.composetable.ui.semantics.TableSemanticsKt +-dontwarn org.dhis2.ui.buttons.FAButtonKt +-dontwarn org.dhis2.ui.dialogs.bottomsheet.BottomSheetDialog +-dontwarn org.dhis2.ui.dialogs.bottomsheet.BottomSheetDialogUiModel +-dontwarn org.dhis2.ui.dialogs.bottomsheet.DialogButtonStyle$DiscardButton +-dontwarn org.dhis2.ui.dialogs.bottomsheet.DialogButtonStyle$MainButton +-dontwarn org.dhis2.ui.dialogs.bottomsheet.DialogButtonStyle +-dontwarn org.dhis2.composetable.model.RowHeader +-dontwarn org.dhis2.composetable.model.TableHeader +-dontwarn org.dhis2.composetable.model.TableHeaderCell +-dontwarn org.dhis2.composetable.model.TableHeaderRow +-dontwarn org.dhis2.composetable.model.TableModel +-dontwarn org.dhis2.composetable.model.TableRowModel \ No newline at end of file diff --git a/tracker/build.gradle.kts b/tracker/build.gradle.kts index 65d915b6ea..be4bd17bba 100644 --- a/tracker/build.gradle.kts +++ b/tracker/build.gradle.kts @@ -19,7 +19,7 @@ android { buildTypes { getByName("release") { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/tracker/proguard-rules.pro b/tracker/proguard-rules.pro index 481bb43481..8a0dc3d157 100644 --- a/tracker/proguard-rules.pro +++ b/tracker/proguard-rules.pro @@ -14,8 +14,8 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable # 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 \ No newline at end of file diff --git a/ui-components/build.gradle.kts b/ui-components/build.gradle.kts index 1021429abc..ddcfe1365e 100644 --- a/ui-components/build.gradle.kts +++ b/ui-components/build.gradle.kts @@ -26,11 +26,9 @@ android { getByName("debug") { } getByName("release") { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( - getDefaultProguardFile( - "proguard-android-optimize.txt" - ), + getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } diff --git a/ui-components/proguard-rules.pro b/ui-components/proguard-rules.pro index ff59496d81..466966b253 100644 --- a/ui-components/proguard-rules.pro +++ b/ui-components/proguard-rules.pro @@ -14,8 +14,8 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable # 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 \ No newline at end of file diff --git a/viewpagerdotsindicator/build.gradle.kts b/viewpagerdotsindicator/build.gradle.kts index d197597c30..9ebd5bd996 100644 --- a/viewpagerdotsindicator/build.gradle.kts +++ b/viewpagerdotsindicator/build.gradle.kts @@ -9,11 +9,13 @@ android { defaultConfig { minSdk = libs.versions.minSdk.get().toInt() testOptions.targetSdk = libs.versions.sdk.get().toInt() + + consumerProguardFiles("consumer-rules.pro") } namespace = "com.tbuonomo.viewpagerdotsindicator" buildTypes { getByName("release") { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"