Skip to content

Commit 9729130

Browse files
Introduce product flavors and streamline build configuration
This commit refactors the `app/build.gradle.kts` file to use product flavors for managing different build variants (prod, beta, alpha, nightly), replacing the previous manual configuration based on a `type` variable. The key changes include: - **Product Flavors**: Introduced a `channel` flavor dimension with `prod`, `beta`, `alpha`, and `nightly` flavors. Each flavor now defines its own `applicationId` and `resValue` for `app_name`. - **Versioning Cleanup**: Removed the logic that manually constructed `versionName` and `applicationId` based on a `type` variable. The base version name is now set directly, and suffixes like `-beta` are applied through product flavors. - **APK Naming Convention**: Simplified and standardized the output APK file naming to the format: `${appId}_${buildType}_${version}.apk`. - **Code Organization**: Added section comments to `build.gradle.kts` for better readability, grouping configurations for versioning, Android, Kotlin, KSP, and dependencies. - **Dependency Comments**: Removed redundant comments from the dependencies block (e.g., "// Core libraries", "// UI Components").
1 parent 0a17c56 commit 9729130

File tree

1 file changed

+89
-84
lines changed

1 file changed

+89
-84
lines changed

app/build.gradle.kts

Lines changed: 89 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,99 +5,107 @@ plugins {
55
alias(libs.plugins.ksp)
66
}
77

8-
// Top of build.gradle.kts
8+
// =========================
9+
// Version configuration
10+
// =========================
11+
912
val major = 1
1013
val minor = 11
1114
val patch = 3
1215
val build = 3
1316

14-
val type = 0 // 1=beta, 2=alpha else=production
15-
1617
val baseVersionName = "$major.$minor.$patch"
1718

18-
val versionCodeInt =
19-
(String.format("%02d", major) + String.format("%02d", minor) + String.format(
20-
"%02d",
21-
patch
22-
) + String.format("%02d", build)).toInt()
19+
val versionCodeBase =
20+
(String.format("%02d", major) +
21+
String.format("%02d", minor) +
22+
String.format("%02d", patch) +
23+
String.format("%02d", build)).toInt()
2324

24-
val versionNameStr = when (type) {
25-
1 -> "$baseVersionName-beta build $build"
26-
2 -> "$baseVersionName-alpha build $build"
27-
else -> "$baseVersionName build $build"
28-
}
29-
30-
val applicationName = when (type) {
31-
1 -> "app.mlauncher.beta"
32-
2 -> "app.mlauncher.alpha"
33-
else -> "app.mlauncher"
34-
}
25+
// =========================
26+
// Android configuration
27+
// =========================
3528

3629
android {
3730
namespace = "com.github.codeworkscreativehub.mlauncher"
38-
compileSdk {
39-
version = release(36)
40-
}
31+
32+
compileSdk = 36
4133

4234
defaultConfig {
43-
applicationId = applicationName
4435
minSdk = 28
4536
targetSdk = 36
46-
versionCode = versionCodeInt
47-
versionName = versionNameStr
37+
versionCode = versionCodeBase
38+
versionName = baseVersionName
4839
}
4940

50-
dependenciesInfo {
51-
includeInApk = false
52-
includeInBundle = false
41+
flavorDimensions += "channel"
42+
43+
productFlavors {
44+
create("prod") {
45+
dimension = "channel"
46+
applicationId = "app.mlauncher"
47+
resValue("string", "app_name", "Multi Launcher")
48+
}
49+
50+
create("beta") {
51+
dimension = "channel"
52+
applicationId = "app.mlauncher.beta"
53+
versionNameSuffix = "-beta"
54+
resValue("string", "app_name", "Multi Launcher Beta")
55+
}
56+
57+
create("alpha") {
58+
dimension = "channel"
59+
applicationId = "app.mlauncher.alpha"
60+
versionNameSuffix = "-alpha"
61+
resValue("string", "app_name", "Multi Launcher Alpha")
62+
}
63+
64+
create("nightly") {
65+
dimension = "channel"
66+
applicationId = "app.mlauncher.nightly"
67+
versionNameSuffix = "-nightly"
68+
resValue("string", "app_name", "Multi Launcher Nightly")
69+
}
5370
}
5471

5572
buildTypes {
5673
getByName("debug") {
74+
isDebuggable = true
5775
isMinifyEnabled = false
5876
isShrinkResources = false
59-
isDebuggable = true
6077
applicationIdSuffix = ".dev"
61-
proguardFiles(
62-
getDefaultProguardFile("proguard-android-optimize.txt"),
63-
"proguard-rules.pro"
64-
)
65-
resValue("string", "app_name", "Multi Launcher Dev")
66-
resValue("string", "app_version", versionNameStr)
78+
79+
resValue("string", "app_version", baseVersionName)
6780
resValue("string", "empty", "")
6881
}
6982

7083
getByName("release") {
7184
isMinifyEnabled = true
7285
isShrinkResources = true
86+
7387
proguardFiles(
7488
getDefaultProguardFile("proguard-android-optimize.txt"),
7589
"proguard-rules.pro"
7690
)
77-
resValue("string", "app_name", "Multi Launcher")
78-
resValue("string", "app_version", versionNameStr)
91+
92+
resValue("string", "app_version", baseVersionName)
7993
resValue("string", "empty", "")
8094
}
8195
}
8296

8397
applicationVariants.all {
84-
if (buildType.name == "release") {
85-
outputs.all {
86-
val output = this as? com.android.build.gradle.internal.api.BaseVariantOutputImpl
87-
if (output?.outputFileName?.endsWith(".apk") == true) {
88-
output.outputFileName =
89-
"${defaultConfig.applicationId}_v${defaultConfig.versionName}-Signed.apk"
90-
}
91-
}
92-
}
93-
if (buildType.name == "debug") {
94-
outputs.all {
95-
val output = this as? com.android.build.gradle.internal.api.BaseVariantOutputImpl
96-
if (output?.outputFileName?.endsWith(".apk") == true) {
97-
output.outputFileName =
98-
"${defaultConfig.applicationId}_v${defaultConfig.versionName}-Debug.apk"
99-
}
100-
}
98+
99+
val appId = this.applicationId
100+
val buildType = this.buildType.name
101+
val version = this.versionName
102+
103+
outputs.all {
104+
val output =
105+
this as com.android.build.gradle.internal.api.BaseVariantOutputImpl
106+
107+
output.outputFileName =
108+
"${appId}_${buildType}_${version}.apk"
101109
}
102110
}
103111

@@ -117,30 +125,41 @@ android {
117125
}
118126

119127
packaging {
120-
// Keep debug symbols for specific native libraries
121-
// found in /app/build/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib
122128
jniLibs {
123-
keepDebugSymbols.add("libandroidx.graphics.path.so") // Ensure debug symbols are kept
129+
keepDebugSymbols.add("libandroidx.graphics.path.so")
124130
}
125131
}
126132
}
127133

134+
// =========================
135+
// Kotlin
136+
// =========================
137+
128138
kotlin {
129139
jvmToolchain(17)
130140

131141
compilerOptions {
132-
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
142+
jvmTarget.set(
143+
org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
144+
)
133145
}
134146
}
135147

136-
// KSP configuration
148+
// =========================
149+
// KSP
150+
// =========================
151+
137152
ksp {
138153
arg("room.schemaLocation", "$projectDir/schemas")
139154
}
140155

156+
// =========================
157+
// Dependencies
158+
// =========================
159+
141160
dependencies {
142161
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
143-
// Core libraries
162+
144163
implementation(libs.core.ktx)
145164
implementation(libs.appcompat)
146165
implementation(libs.recyclerview)
@@ -151,60 +170,46 @@ dependencies {
151170
implementation(libs.activity)
152171
implementation(libs.commons.text)
153172

154-
// Android Lifecycle
155173
implementation(libs.lifecycle.extensions)
156174
implementation(libs.lifecycle.viewmodel.ktx)
157175

158-
// Navigation
159176
implementation(libs.navigation.fragment.ktx)
160177
implementation(libs.navigation.ui.ktx)
161178

162-
// Work Manager
163179
implementation(libs.work.runtime.ktx)
164180

165-
// UI Components
166181
implementation(libs.constraintlayout)
167182
implementation(libs.constraintlayout.compose)
168183
implementation(libs.activity.compose)
169184

170-
// Jetpack Compose
171-
implementation(libs.compose.material) // Compose Material Design
172-
implementation(libs.compose.android) // Android
173-
implementation(libs.compose.animation) // Animations
174-
implementation(libs.compose.ui) // Core UI library
175-
implementation(libs.compose.foundation) // Foundation library
176-
implementation(libs.compose.ui.tooling) // UI tooling for previews
185+
implementation(libs.compose.material)
186+
implementation(libs.compose.android)
187+
implementation(libs.compose.animation)
188+
implementation(libs.compose.ui)
189+
implementation(libs.compose.foundation)
190+
implementation(libs.compose.ui.tooling)
177191

178-
// Biometric support
179192
implementation(libs.biometric.ktx)
180193

181-
// Moshi
182194
implementation(libs.moshi)
183195
implementation(libs.moshi.ktx)
184196
ksp(libs.moshi.codegen)
185197

186-
// Room
187198
implementation(libs.room.runtime)
188199
implementation(libs.room.ktx)
189200
ksp(libs.room.compiler)
190201

191-
// AndroidX Test - Espresso
192202
androidTestImplementation(libs.espresso.core)
193203
androidTestImplementation(libs.espresso.contrib)
194-
implementation(libs.espresso.idling.resource) // Idling resources for Espresso tests
204+
implementation(libs.espresso.idling.resource)
195205

196-
// Test rules and other testing dependencies
197206
androidTestImplementation(libs.test.runner)
198207
androidTestImplementation(libs.test.rules)
199-
implementation(libs.test.core.ktx) // Test core utilities
208+
implementation(libs.test.core.ktx)
200209

201-
// Jetpack Compose Testing
202-
androidTestImplementation(libs.ui.test.junit4) // For createComposeRule
203-
debugImplementation(libs.ui.test.manifest) // Debug-only dependencies for Compose testing
210+
androidTestImplementation(libs.ui.test.junit4)
211+
debugImplementation(libs.ui.test.manifest)
204212

205-
// Fragment testing
206213
debugImplementation(libs.fragment.testing)
207-
208-
// Navigation testing
209214
androidTestImplementation(libs.navigation.testing)
210215
}

0 commit comments

Comments
 (0)