Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: activate shrink and minify in app #3906

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipeline {
steps {
script {
echo 'Building UI APKs'
sh './gradlew :app:assembleDhisUITestingDebug :app:assembleDhisUITestingDebugAndroidTest :compose-table:assembleAndroidTest :form:assembleAndroidTest'
sh './gradlew :app:assembleDhisDebug :app:assembleDhisDebugAndroidTest :compose-table:assembleAndroidTest :form:assembleAndroidTest'
}
}
}
Expand Down
13 changes: 3 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -143,9 +142,10 @@ android {
buildConfigField("String", "GIT_SHA", "\"" + getCommitHash() + "\"")
}
getByName("release") {
isMinifyEnabled = false
isShrinkResources = true
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android.txt"),
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
Expand All @@ -170,13 +170,6 @@ android {
versionCode = libs.versions.vCode.get().toInt()
versionName = libs.versions.vName.get()
}

create("dhisUITesting") {
applicationId = "com.dhis2"
dimension = "default"
versionCode = libs.versions.vCode.get().toInt()
versionName = libs.versions.vName.get()
}
}

compileOptions {
Expand Down
226 changes: 224 additions & 2 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,230 @@

# 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
-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
-dontwarn java.lang.management.ManagementFactory
-dontwarn javax.lang.model.SourceVersion
-dontwarn javax.lang.model.element.Element
-dontwarn javax.lang.model.element.Modifier
-dontwarn javax.lang.model.type.TypeMirror
-dontwarn javax.lang.model.type.TypeVisitor
-dontwarn javax.lang.model.util.SimpleTypeVisitor7
-dontwarn javax.management.InstanceAlreadyExistsException
-dontwarn javax.management.MBeanServer
-dontwarn javax.management.ObjectInstance
-dontwarn javax.management.ObjectName
-dontwarn javax.naming.Context
-dontwarn javax.naming.InitialContext
-dontwarn javax.naming.NameNotFoundException
-dontwarn javax.naming.NoInitialContextException
-dontwarn org.apache.harmony.xnet.provider.jsse.SSLParametersImpl
-dontwarn org.bouncycastle.jsse.BCSSLParameters
-dontwarn org.bouncycastle.jsse.BCSSLSocket
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
-dontwarn org.dhis2.tracker.NavigationBarUIState
-dontwarn org.dhis2.tracker.TEIDashboardItems
-dontwarn org.dhis2.tracker.data.ProfilePictureProvider
-dontwarn org.dhis2.tracker.events.CreateEventUseCase
-dontwarn org.dhis2.tracker.events.CreateEventUseCaseRepository
-dontwarn org.dhis2.tracker.relationships.data.EventRelationshipsRepository
-dontwarn org.dhis2.tracker.relationships.data.RelationshipsRepository
-dontwarn org.dhis2.tracker.relationships.data.TrackerRelationshipsRepository
-dontwarn org.dhis2.tracker.relationships.domain.DeleteRelationships
-dontwarn org.dhis2.tracker.relationships.domain.GetRelationshipsByType
-dontwarn org.dhis2.tracker.relationships.model.ListSelectionState
-dontwarn org.dhis2.tracker.relationships.model.RelationshipDirection
-dontwarn org.dhis2.tracker.relationships.model.RelationshipItem
-dontwarn org.dhis2.tracker.relationships.model.RelationshipModel
-dontwarn org.dhis2.tracker.relationships.model.RelationshipOwnerType
-dontwarn org.dhis2.tracker.relationships.model.RelationshipSection
-dontwarn org.dhis2.tracker.relationships.model.RelationshipTopBarIconState$List
-dontwarn org.dhis2.tracker.relationships.model.RelationshipTopBarIconState$Map
-dontwarn org.dhis2.tracker.relationships.model.RelationshipTopBarIconState$Selecting
-dontwarn org.dhis2.tracker.relationships.model.RelationshipTopBarIconState
-dontwarn org.dhis2.tracker.relationships.ui.RelationshipsScreenKt
-dontwarn org.dhis2.tracker.relationships.ui.RelationshipsUiState$Success
-dontwarn org.dhis2.tracker.relationships.ui.RelationshipsUiState
-dontwarn org.dhis2.tracker.relationships.ui.RelationshipsViewModel
-dontwarn org.dhis2.tracker.ui.AvatarProvider
-dontwarn org.joda.convert.FromString
-dontwarn org.joda.convert.ToString
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
-dontwarn org.openjsse.net.ssl.OpenJSSE
-dontwarn org.slf4j.impl.StaticLoggerBinder

#AndroidX
-dontwarn com.google.android.material.**
-keep class com.google.android.material.** { *; }

-dontwarn androidx.**
-keep class androidx.** { *; }
-keep interface androidx.* { *; }

#Data binding
-keep class * extends androidx.databinding.DataBinderMapper { *; }
-dontwarn androidx.databinding.**
-keep class androidx.databinding.** { *; }
-keep class * extends androidx.databinding.DataBinderMapper

##---------------Begin: proguard configuration for Gson ----------
# 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.** { <fields>; }

# 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

### Gson ProGuard and R8 rules which are relevant for all users
### This file is automatically recognized by ProGuard and R8, see https://developer.android.com/build/shrink-code#configuration-files
###
### IMPORTANT:
### - These rules are additive; don't include anything here which is not specific to Gson (such as completely
### disabling obfuscation for all classes); the user would be unable to disable that then
### - These rules are not complete; users will most likely have to add additional rules for their specific
### classes, for example to disable obfuscation for certain fields or to keep no-args constructors
###

# Keep generic signatures; needed for correct type resolution
-keepattributes Signature

# Keep Gson annotations
# Note: Cannot perform finer selection here to only cover Gson annotations, see also https://stackoverflow.com/q/47515093
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault

### The following rules are needed for R8 in "full mode" which only adheres to `-keepattribtues` if
### the corresponding class or field is matches by a `-keep` rule as well, see
### https://r8.googlesource.com/r8/+/refs/heads/main/compatibility-faq.md#r8-full-mode

# Keep class TypeToken (respectively its generic signature) if present
-if class com.google.gson.reflect.TypeToken
-keep,allowobfuscation class com.google.gson.reflect.TypeToken

# Keep any (anonymous) classes extending TypeToken
-keep,allowobfuscation class * extends com.google.gson.reflect.TypeToken

# Keep classes with @JsonAdapter annotation
-keep,allowobfuscation,allowoptimization @com.google.gson.annotations.JsonAdapter class *

# Keep fields with any other Gson annotation
# Also allow obfuscation, assuming that users will additionally use @SerializedName or
# other means to preserve the field names
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.Expose <fields>;
@com.google.gson.annotations.JsonAdapter <fields>;
@com.google.gson.annotations.Since <fields>;
@com.google.gson.annotations.Until <fields>;
}

# Keep no-args constructor of classes which can be used with @JsonAdapter
# By default their no-args constructor is invoked to create an adapter instance
-keepclassmembers class * extends com.google.gson.TypeAdapter {
<init>();
}
-keepclassmembers class * implements com.google.gson.TypeAdapterFactory {
<init>();
}
-keepclassmembers class * implements com.google.gson.JsonSerializer {
<init>();
}
-keepclassmembers class * implements com.google.gson.JsonDeserializer {
<init>();
}

# Keep fields annotated with @SerializedName for classes which are referenced.
# If classes with fields annotated with @SerializedName have a no-args
# constructor keep that as well. Based on
# https://issuetracker.google.com/issues/150189783#comment11.
# See also https://github.com/google/gson/pull/2420#discussion_r1241813541
# for a more detailed explanation.
-if class *
-keepclasseswithmembers,allowobfuscation class <1> {
@com.google.gson.annotations.SerializedName <fields>;
}
-if class * {
@com.google.gson.annotations.SerializedName <fields>;
}
-keepclassmembers,allowobfuscation,allowoptimization class <1> {
<init>();
}

-dontwarn java.lang.invoke.StringConcatFactory

# Preserve Kotlin data classes (general rule for data classes)
-keepclasseswithmembers class * {
kotlin.Metadata *;
}

# Keep the Uri class from Android SDK (this is generally safe)
-keep class android.net.Uri {
<init>(...);
public static android.net.Uri parse(java.lang.String);
public *;
}

# Jackson
-keep @com.fasterxml.jackson.annotation.JsonIgnoreProperties class * { *; }
-keep class com.fasterxml.** { *; }
-keep class org.codehaus.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepclassmembers public final enum com.fasterxml.jackson.annotation.JsonAutoDetect$Visibility {
public static final com.fasterxml.jackson.annotation.JsonAutoDetect$Visibility *;
}

# General
-keepattributes SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,Signature,Exceptions,InnerClasses

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn java.beans.ConstructorProperties
-dontwarn java.beans.Transient

#-keep class org.dhis2.usescases.login.auth.AuthServiceModel
-dontwarn org.hisp.dhis.android.core.**
-keep class org.hisp.dhis.android.core.** {*;}

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn javax.management.InstanceNotFoundException
49 changes: 0 additions & 49 deletions app/src/dhisUITesting/java/org/dhis2/bindings/ContextExtensions.kt

This file was deleted.

This file was deleted.

Loading
Loading