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

Commit

Permalink
chore: use private signing key to sign APKs
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Jan 5, 2023
1 parent 2c66d0e commit 9429f36
Show file tree
Hide file tree
Showing 24 changed files with 120 additions and 726 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ jobs:
${{ runner.os }}-gradle-
- name: Assemble Debug
run: ./gradlew assembleDebug
env:
IDE_SIGNING_ALIAS: ${{ secrets.IDE_SIGNING_ALIAS }}
IDE_SIGNING_AUTH_PASS: ${{ secrets.IDE_SIGNING_AUTH_PASS }}
IDE_SIGNING_AUTH_USER: ${{ secrets.IDE_SIGNING_AUTH_USER }}
IDE_SIGNING_KEY_PASS: ${{ secrets.IDE_SIGNING_KEY_PASS }}
IDE_SIGNING_STORE_PASS: ${{ secrets.IDE_SIGNING_STORE_PASS }}
IDE_SIGNING_URL: ${{ secrets.IDE_SIGNING_URL }}
- name: Upload APK
uses: actions/upload-artifact@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Downloaded signing key
signing-key.jks

# Built application files
*.apk
*.aar
Expand Down
4 changes: 4 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Directories that are created when generating signed APK in Android Studio
/debug
/release

# Built application files
*.apk
*.aar
Expand Down
77 changes: 66 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
@file:Suppress("UnstableApiUsage")

import de.undercouch.gradle.tasks.download.DownloadAction

plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
id("kotlin-parcelize")
id("com.google.android.gms.oss-licenses-plugin")
id("de.undercouch.download") version "5.3.0"
}

android {
Expand All @@ -16,21 +21,33 @@ android {

compileOptions { isCoreLibraryDesugaringEnabled = true }

signingConfigs.create("common") {
storeFile = file("dev.keystore")
keyAlias = "androidide"
storePassword = "ed68424fb109e5aa8146e4b86caa72e3"
keyPassword = "ed68424fb109e5aa8146e4b86caa72e3"
}
downloadSigningKey()

// Keystore credentials
val alias = checkAndGetEnv(KEY_ALIAS)
val storePass = checkAndGetEnv(KEY_STORE_PASS)
val keyPass = checkAndGetEnv(KEY_PASS)

buildTypes {
debug { signingConfig = signingConfigs.getByName("common") }
release {
isShrinkResources = true
signingConfig = signingConfigs.getByName("common")
if (alias != null && storePass != null && keyPass != null && signingKey.exists()) {
signingConfigs.create("common") {
storeFile = signingKey
keyAlias = alias
storePassword = storePass
keyPassword = keyPass
}

buildTypes {
debug { signingConfig = signingConfigs.getByName("common") }
release { signingConfig = signingConfigs.getByName("common") }
}
} else {
logger.warn(
"Signing info not configured. keystoreFile=$signingKey[exists=${signingKey.exists()}]"
)
}

buildTypes { release { isShrinkResources = true } }

packagingOptions {
resources.excludes.addAll(
arrayOf(
Expand Down Expand Up @@ -135,3 +152,41 @@ dependencies {
androidTestImplementation(libs.tests.androidx.espresso)
androidTestImplementation(libs.tests.google.truth)
}

fun downloadSigningKey() {
if (signingKey.exists()) {
logger.info("Skipping download as ${signingKey.name} file already exists.")
return
}

// URL to download the signing key
val url = checkAndGetEnv(KEY_URL) ?: return

// Username and password required to download the keystore
val user = checkAndGetEnv(AUTH_USER) ?: return
val pass = checkAndGetEnv(AUTH_PASS) ?: return

logger.info("Downloading signing key...")
DownloadAction(project).apply {
src(url)
dest(signingKey)
username(user)
password(pass)
overwrite(false)

// Must be set to true
quiet(true)
}.execute()

// wait for the download to finish
.get()
}

fun checkAndGetEnv(env: String): String? {
val value = System.getenv(env)
if (value.isNullOrBlank()) {
logger.warn("$env is not set. Debug key will be used to sign the APK")
return null
}
return value
}
1 change: 0 additions & 1 deletion app/release/app-release.apk.cache/code-version

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed app/release/app-release.apk.cache/names-map
Binary file not shown.
33 changes: 0 additions & 33 deletions app/release/app-release.apk.cache/sources/17/00003017.java

This file was deleted.

6 changes: 0 additions & 6 deletions app/release/app-release.apk.cache/sources/18/00003018.java

This file was deleted.

Loading

0 comments on commit 9429f36

Please sign in to comment.