Skip to content

Commit a224650

Browse files
committed
build: add more app shrinking settings
1 parent 2fdbff5 commit a224650

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

app/build.gradle.kts

+31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@file:Suppress("UnstableApiUsage")
66

77
plugins {
8+
id("com.osfans.trime.app-convention")
89
id("com.osfans.trime.native-app-convention")
910
id("com.osfans.trime.data-checksums")
1011
id("com.osfans.trime.native-cache-hash")
@@ -61,6 +62,11 @@ android {
6162

6263
resValue("string", "trime_app_name", "@string/app_name_debug")
6364
}
65+
all {
66+
// remove META-INF/version-control-info.textproto
67+
@Suppress("UnstableApiUsage")
68+
vcsInfo.include = false
69+
}
6470
}
6571

6672
buildFeatures {
@@ -87,6 +93,24 @@ android {
8793
it.useJUnitPlatform()
8894
}
8995
}
96+
97+
dependenciesInfo {
98+
includeInApk = false
99+
includeInBundle = false
100+
}
101+
102+
packaging {
103+
resources {
104+
excludes +=
105+
setOf(
106+
"/META-INF/*.version",
107+
"/META-INF/*.kotlin_module", // cannot be excluded actually
108+
"/META-INF/androidx/**",
109+
"/DebugProbesKt.bin",
110+
"/kotlin-tooling-metadata.json",
111+
)
112+
}
113+
}
90114
}
91115

92116
kotlin {
@@ -155,3 +179,10 @@ dependencies {
155179
testImplementation(libs.kotest.assertions.core)
156180
androidTestImplementation(libs.junit)
157181
}
182+
183+
configurations {
184+
all {
185+
// remove Baseline Profile Installer or whatever it is...
186+
exclude(group = "androidx.profileinstaller", module = "profileinstaller")
187+
}
188+
}

build-logic/convention/build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ dependencies {
1717

1818
gradlePlugin {
1919
plugins {
20+
register("androidAppConvention") {
21+
id = "com.osfans.trime.app-convention"
22+
implementationClass = "AndroidAppConventionPlugin"
23+
}
2024
register("dataChecksums") {
2125
id = "com.osfans.trime.data-checksums"
2226
implementationClass = "DataChecksumsPlugin"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015 - 2025 Rime community
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
import com.android.build.gradle.internal.tasks.CompileArtProfileTask
6+
import com.android.build.gradle.internal.tasks.ExpandArtProfileWildcardsTask
7+
import com.android.build.gradle.internal.tasks.MergeArtProfileTask
8+
import com.android.build.gradle.tasks.PackageApplication
9+
import org.gradle.api.Plugin
10+
import org.gradle.api.Project
11+
import org.gradle.api.file.RegularFile
12+
import org.gradle.api.internal.provider.AbstractProperty
13+
import org.gradle.api.internal.provider.Providers
14+
import org.gradle.kotlin.dsl.withType
15+
16+
class AndroidAppConventionPlugin : Plugin<Project> {
17+
override fun apply(target: Project) {
18+
// remove META-INF/com/android/build/gradle/app-metadata.properties
19+
target.tasks.withType<PackageApplication> {
20+
val valueField =
21+
AbstractProperty::class.java.declaredFields.find { it.name == "value" } ?: run {
22+
println("class AbstractProperty field value not found, something could have gone wrong")
23+
return@withType
24+
}
25+
valueField.isAccessible = true
26+
doFirst {
27+
valueField.set(appMetadata, Providers.notDefined<RegularFile>())
28+
allInputFilesWithNameOnlyPathSensitivity.removeAll { true }
29+
}
30+
}
31+
32+
// remove assets/dexopt/baseline.prof{,m} (baseline profile)
33+
target.tasks.withType<MergeArtProfileTask> { enabled = false }
34+
target.tasks.withType<ExpandArtProfileWildcardsTask> { enabled = false }
35+
target.tasks.withType<CompileArtProfileTask> { enabled = false }
36+
}
37+
}

0 commit comments

Comments
 (0)