Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 9429f36

Browse files
committed
chore: use private signing key to sign APKs
1 parent 2c66d0e commit 9429f36

File tree

24 files changed

+120
-726
lines changed

24 files changed

+120
-726
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ jobs:
4444
${{ runner.os }}-gradle-
4545
- name: Assemble Debug
4646
run: ./gradlew assembleDebug
47+
env:
48+
IDE_SIGNING_ALIAS: ${{ secrets.IDE_SIGNING_ALIAS }}
49+
IDE_SIGNING_AUTH_PASS: ${{ secrets.IDE_SIGNING_AUTH_PASS }}
50+
IDE_SIGNING_AUTH_USER: ${{ secrets.IDE_SIGNING_AUTH_USER }}
51+
IDE_SIGNING_KEY_PASS: ${{ secrets.IDE_SIGNING_KEY_PASS }}
52+
IDE_SIGNING_STORE_PASS: ${{ secrets.IDE_SIGNING_STORE_PASS }}
53+
IDE_SIGNING_URL: ${{ secrets.IDE_SIGNING_URL }}
4754
- name: Upload APK
4855
uses: actions/upload-artifact@v3
4956
with:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Downloaded signing key
2+
signing-key.jks
3+
14
# Built application files
25
*.apk
36
*.aar

app/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Directories that are created when generating signed APK in Android Studio
2+
/debug
3+
/release
4+
15
# Built application files
26
*.apk
37
*.aar

app/build.gradle.kts

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
@file:Suppress("UnstableApiUsage")
2+
3+
import de.undercouch.gradle.tasks.download.DownloadAction
4+
15
plugins {
26
id("com.android.application")
37
id("kotlin-android")
48
id("kotlin-kapt")
59
id("kotlin-parcelize")
610
id("com.google.android.gms.oss-licenses-plugin")
11+
id("de.undercouch.download") version "5.3.0"
712
}
813

914
android {
@@ -16,21 +21,33 @@ android {
1621

1722
compileOptions { isCoreLibraryDesugaringEnabled = true }
1823

19-
signingConfigs.create("common") {
20-
storeFile = file("dev.keystore")
21-
keyAlias = "androidide"
22-
storePassword = "ed68424fb109e5aa8146e4b86caa72e3"
23-
keyPassword = "ed68424fb109e5aa8146e4b86caa72e3"
24-
}
24+
downloadSigningKey()
25+
26+
// Keystore credentials
27+
val alias = checkAndGetEnv(KEY_ALIAS)
28+
val storePass = checkAndGetEnv(KEY_STORE_PASS)
29+
val keyPass = checkAndGetEnv(KEY_PASS)
2530

26-
buildTypes {
27-
debug { signingConfig = signingConfigs.getByName("common") }
28-
release {
29-
isShrinkResources = true
30-
signingConfig = signingConfigs.getByName("common")
31+
if (alias != null && storePass != null && keyPass != null && signingKey.exists()) {
32+
signingConfigs.create("common") {
33+
storeFile = signingKey
34+
keyAlias = alias
35+
storePassword = storePass
36+
keyPassword = keyPass
3137
}
38+
39+
buildTypes {
40+
debug { signingConfig = signingConfigs.getByName("common") }
41+
release { signingConfig = signingConfigs.getByName("common") }
42+
}
43+
} else {
44+
logger.warn(
45+
"Signing info not configured. keystoreFile=$signingKey[exists=${signingKey.exists()}]"
46+
)
3247
}
3348

49+
buildTypes { release { isShrinkResources = true } }
50+
3451
packagingOptions {
3552
resources.excludes.addAll(
3653
arrayOf(
@@ -135,3 +152,41 @@ dependencies {
135152
androidTestImplementation(libs.tests.androidx.espresso)
136153
androidTestImplementation(libs.tests.google.truth)
137154
}
155+
156+
fun downloadSigningKey() {
157+
if (signingKey.exists()) {
158+
logger.info("Skipping download as ${signingKey.name} file already exists.")
159+
return
160+
}
161+
162+
// URL to download the signing key
163+
val url = checkAndGetEnv(KEY_URL) ?: return
164+
165+
// Username and password required to download the keystore
166+
val user = checkAndGetEnv(AUTH_USER) ?: return
167+
val pass = checkAndGetEnv(AUTH_PASS) ?: return
168+
169+
logger.info("Downloading signing key...")
170+
DownloadAction(project).apply {
171+
src(url)
172+
dest(signingKey)
173+
username(user)
174+
password(pass)
175+
overwrite(false)
176+
177+
// Must be set to true
178+
quiet(true)
179+
}.execute()
180+
181+
// wait for the download to finish
182+
.get()
183+
}
184+
185+
fun checkAndGetEnv(env: String): String? {
186+
val value = System.getenv(env)
187+
if (value.isNullOrBlank()) {
188+
logger.warn("$env is not set. Debug key will be used to sign the APK")
189+
return null
190+
}
191+
return value
192+
}

app/release/app-release.apk.cache/code-version

Lines changed: 0 additions & 1 deletion
This file was deleted.
-3.94 KB
Binary file not shown.
-88 Bytes
Binary file not shown.
-21.7 KB
Binary file not shown.
-2.34 KB
Binary file not shown.
-13.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)