Skip to content

Commit 6f8cdc9

Browse files
Prioritize local keystore over CI/CD keystore
This commit refactors the signing configuration in `build.gradle.kts` to prioritize a local keystore file (`mLauncher.jks`) if it exists. The CI/CD-provided keystore, decoded from a Base64 environment variable, will now be used as a fallback. The changes include: - Logic to check for `app/mLauncher.jks` before attempting to create the temporary keystore for CI environments. - A new validation step that throws a `GradleException` if the decoded keystore from the environment variable is smaller than 1024 bytes. - Additional logging to print the path and size of the keystore being used for the release build.
1 parent 9339517 commit 6f8cdc9

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

app/build.gradle.kts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,31 @@ android {
8282
System.getenv("KEY_PASSWORD") ?: throw GradleException("KEY_PASSWORD not set")
8383

8484
// Use file helper to ensure correct path
85-
val keystoreFile = layout.buildDirectory.file("temp-keystore.jks").get().asFile
85+
val localKeystore = rootProject.file("app/mLauncher.jks")
86+
val ciKeystore = layout.buildDirectory.file("temp-keystore.jks").get().asFile
87+
88+
val keystoreFile = when {
89+
localKeystore.exists() -> localKeystore
90+
else -> ciKeystore
91+
}
8692

8793
if (!keystoreFile.exists()) {
88-
// Ensure parent directories exist
8994
keystoreFile.parentFile.mkdirs()
95+
9096
val bytes = Base64.getDecoder().decode(keystoreB64)
97+
98+
if (bytes.size < 1024) {
99+
throw GradleException("Decoded keystore is too small (${bytes.size} bytes)")
100+
}
101+
91102
keystoreFile.writeBytes(bytes)
92103
}
93104

105+
println("Using keystore: ${keystoreFile.absolutePath} (${keystoreFile.length()} bytes)")
106+
94107
create("release") {
95-
this.storeFile = keystoreFile
96-
this.storePassword = keystorePassword
108+
storeFile = keystoreFile
109+
storePassword = keystorePassword
97110
this.keyAlias = keyAlias
98111
this.keyPassword = keyPassword
99112
}

0 commit comments

Comments
 (0)