Skip to content

Commit

Permalink
feat(cli): setup Android signing
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 4, 2024
1 parent f955f7b commit 8acfa34
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/android-signing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:feat
"@tauri-apps/cli": patch:feat
---

Setup Android signing by reading the `src-tauri/gen/android/keystore.properties` file which should have the `keyAlias=<key-alias>`, `password=<keystore-password>`, `storeFile=<path/to/keystore.jks>` key value pairs separated by new lines.
4 changes: 3 additions & 1 deletion tooling/cli/templates/mobile/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ local.properties
key.properties

/.tauri
/tauri.settings.gradle
/tauri.settings.gradle

keystore.properties
19 changes: 19 additions & 0 deletions tooling/cli/templates/mobile/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.util.Properties
import java.io.FileInputStream

plugins {
id("com.android.application")
Expand All @@ -8,6 +9,15 @@ plugins {
id("{{this}}"){{/each}}
}

val keystoreProperties = Properties()
try {
// release builds require the file to be set up
keystoreProperties.load(FileInputStream(rootProject.file("keystore.properties")))
} catch (e: Exception) {
// load a dummy file for debug purposes (signing config won't be used)
keystoreProperties.load(FileInputStream(rootProject.file("keystore.properties.dummy")))
}

val tauriProperties = Properties().apply {
val propFile = file("tauri.properties")
if (propFile.exists()) {
Expand All @@ -26,6 +36,14 @@ android {
versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt()
versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0")
}
signingConfigs {
create("release") {
keyAlias = keystoreProperties["keyAlias"] as String
keyPassword = keystoreProperties["password"] as String
storeFile = file(keystoreProperties["storeFile"] as String)
storePassword = keystoreProperties["password"] as String
}
}
buildTypes {
getByName("debug") {
manifestPlaceholders["usesCleartextTraffic"] = "true"
Expand All @@ -45,6 +63,7 @@ android {
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
.toList().toTypedArray()
)
signingConfig = signingConfigs.getByName("release")
}
}
kotlinOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
keyAlias=tauri-dummy
password=dummy-pwd
storeFile=./dummy-keystore.jks

0 comments on commit 8acfa34

Please sign in to comment.