Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
20 changes: 20 additions & 0 deletions .github/workflows/test-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ jobs:
env:
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}

- name: setup Android signing secrets
working-directory: ./examples/api/src-tauri/gen/android
run: |
echo "keyAlias=${{ secrets.ANDROID_KEY_ALIAS }}" > keystore.properties
echo "password=${{ secrets.ANDROID_KEY_PASSWORD }}" >> keystore.properties

- name: setup Android signing key (Unix)
if: matrix.platform != 'windows-latest'
working-directory: ./examples/api/src-tauri/gen/android
run: |
base64 -d <<< "${{ secrets.ANDROID_KEY_BASE64 }}" > $RUNNER_TEMP/keystore.jks
echo "storeFile=$RUNNER_TEMP/keystore.jks" >> keystore.properties

- name: setup Android signing key (Windows)
if: matrix.platform == 'windows-latest'
working-directory: ./examples/api/src-tauri/gen/android
run: |
[System.Convert]::FromBase64String("${{ secrets.ANDROID_KEY_BASE64 }}") | Set-Content $env:RUNNER_TEMP\keystore.jks -AsByteStream
echo "storeFile=$env:RUNNER_TEMP\keystore.jks" >> keystore.properties

- name: build APK
working-directory: ./examples/api
run: cargo tauri android build
Expand Down
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")))
}
Comment on lines +12 to +19

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should just include keystore.properties by default instead of the dummy one, or even just remove this altogether and just document how users might want to add signing later on if they wish.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd be fine with this on docs instead @FabianLars @simonhyll

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to be in the docs but was lost in recent refactors of tauri documentation and whether we merge this PR or not, I think we will still need to have it documented


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