From 9f982875fee53434afaf5f9eaf38f9ad1f6731a4 Mon Sep 17 00:00:00 2001 From: Seb3thehacker Date: Wed, 14 Oct 2026 13:29:00 -0700 Subject: [PATCH] release builds shrink with R8: 65 MB down to 30 MB, small enough for IzzyOnDroid. -Pr8 does the same to a debug build for testing --- gearslip/build.gradle.kts | 20 +++++++++++++++----- gearslip/proguard-rules.pro | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 gearslip/proguard-rules.pro diff --git a/gearslip/build.gradle.kts b/gearslip/build.gradle.kts index 2a3561e..0b776e8 100644 --- a/gearslip/build.gradle.kts +++ b/gearslip/build.gradle.kts @@ -24,6 +24,12 @@ val keystoreProperties = Properties().apply { ).firstOrNull { it.exists() }?.inputStream()?.use { load(it) } } +// Keeps build output out of the module folder: /build/gearslip/... instead of +// /gearslip/build/..., so everything this project produces lands under one +// root-level build/ directory. Set before android {}, which works out the path to R8's default +// rules from it. +layout.buildDirectory.set(rootProject.layout.buildDirectory.dir("gearslip")) + android { namespace = "app.seb3thehacker.gearslip" compileSdk = 37 @@ -57,6 +63,9 @@ android { buildTypes { release { signingConfig = signingConfigs.findByName("release") + isMinifyEnabled = true + isShrinkResources = true + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") } // Its own package, so a debug build installs beside the release one instead of over it. // Signed with the release key when it's here: both builds declare the car template @@ -65,6 +74,12 @@ android { applicationIdSuffix = ".dev" signingConfigs.findByName("release")?.let { signingConfig = it } manifestPlaceholders["appLabel"] = "Gearslip Debug" + // -Pr8 shrinks a debug build like a release one, to test R8 in the debug install. + if (project.hasProperty("r8")) { + isMinifyEnabled = true + isShrinkResources = true + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } } } @@ -72,11 +87,6 @@ android { buildConfig = true } - // Keeps build output out of the module folder: /build/gearslip/... instead of - // /gearslip/build/..., so everything this project produces lands under one - // root-level build/ directory. - layout.buildDirectory.set(rootProject.layout.buildDirectory.dir("gearslip")) - compileOptions { sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 diff --git a/gearslip/proguard-rules.pro b/gearslip/proguard-rules.pro new file mode 100644 index 0000000..b833500 --- /dev/null +++ b/gearslip/proguard-rules.pro @@ -0,0 +1,20 @@ +# R8 shrinks the release build; these keep what it can't see being used. + +# Names stay readable, so stack traces in shared logs need no mapping file. Shrinking does +# the real work on size. +-dontobfuscate + +# Gearslip hosts other apps' car screens: their templates arrive as Bundles, and the car +# library rebuilds them by class name and reflection. Any model class an app might send has to +# survive, used by Gearslip's code or not. +-keep class androidx.car.app.** { *; } + +# Speech-to-text: the native library calls back into these classes by name. +-keep class com.k2fsa.sherpa.onnx.** { *; } + +# commons-compress refers to optional codecs Gearslip doesn't ship. +-dontwarn org.tukaani.xz.** +-dontwarn com.github.luben.zstd.** +-dontwarn org.brotli.dec.** +-dontwarn org.objectweb.asm.** +-dontwarn org.osgi.**