From 69ff9b531c01896cbbcd1e30bbda7881e8cee824 Mon Sep 17 00:00:00 2001 From: Diamond <33725716+DiamondMiner88@users.noreply.github.com> Date: Sun, 18 Sep 2022 12:42:27 -0700 Subject: [PATCH] perf: increase release optimizations --- app/build.gradle.kts | 22 ++++++++++++++++++++++ app/proguard-rules.pro | 26 ++++++++++++++++++++++++++ gradle.properties | 6 ++++++ 3 files changed, 54 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index edd3516..0996220 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -31,6 +31,28 @@ android { } } + androidComponents { + onVariants(selector().withBuildType("release")) { + it.packaging.resources.excludes.apply { + // Debug metadata + add("/**/*.version") + add("/kotlin-tooling-metadata.json") + // Kotlin debugging (https://github.com/Kotlin/kotlinx.coroutines/issues/2274) + add("/DebugProbesKt.bin") + } + } + } + + packagingOptions { + resources { + // Reflection symbol list (https://stackoverflow.com/a/41073782/13964629) + excludes += "/**/*.kotlin_builtins" + + // okhttp3 is used by some lib (no cookies so publicsuffixes.gz can be dropped) + excludes += "/okhttp3/**" + } + } + compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 1ea4fee..4c8cbd7 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -24,3 +24,29 @@ # @Serializable and @Polymorphic are used at runtime for polymorphic serialization. -keepattributes RuntimeVisibleAnnotations,AnnotationDefault + +# Serializer for classes with named companion objects are retrieved using `getDeclaredClasses`. +# If you have any, uncomment and replace classes with those containing named companion objects. +-keepattributes InnerClasses # Needed for `getDeclaredClasses`. +#-if @kotlinx.serialization.Serializable class +#com.xinto.opencord.gateway.io.OpCode, # <-- List serializable classes with named companions. +#com.xinto.opencord.gateway.io.EventName +#{ +# static **$* *; +#} +-keepnames class <1>$$serializer { # -keepnames suffices; class is kept when serializer() is kept. + static <1>$$serializer INSTANCE; +} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +-keepattributes SourceFile,LineNumberTable + +# Repackage classes into the top-level. +-repackageclasses + +# Amount of optimization iterations, taken from an SO post +-optimizationpasses 5 + +# Broaden access modifiers to increase results during optimization +-allowaccessmodification diff --git a/gradle.properties b/gradle.properties index f20a521..b1004f6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,13 +7,19 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 + # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + # AndroidX package structure to make it clearer which packages are bundled with the # Android operating system, and which are packaged with your app"s APK # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true + # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official + +# Enable R8 full mode. +android.enableR8.fullMode=true