diff --git a/.changes/android-signing.md b/.changes/android-signing.md new file mode 100644 index 000000000000..30626d935bdf --- /dev/null +++ b/.changes/android-signing.md @@ -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=`, `password=`, `storeFile=` key value pairs separated by new lines. diff --git a/.github/workflows/test-android.yml b/.github/workflows/test-android.yml index 0a3fdbda78e3..fd2f88f2ea87 100644 --- a/.github/workflows/test-android.yml +++ b/.github/workflows/test-android.yml @@ -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 diff --git a/tooling/cli/templates/mobile/android/.gitignore b/tooling/cli/templates/mobile/android/.gitignore index b24820317285..4c2fae474088 100644 --- a/tooling/cli/templates/mobile/android/.gitignore +++ b/tooling/cli/templates/mobile/android/.gitignore @@ -16,4 +16,6 @@ local.properties key.properties /.tauri -/tauri.settings.gradle \ No newline at end of file +/tauri.settings.gradle + +keystore.properties diff --git a/tooling/cli/templates/mobile/android/app/build.gradle.kts b/tooling/cli/templates/mobile/android/app/build.gradle.kts index c29afc0e7ec3..d08499f54ab1 100644 --- a/tooling/cli/templates/mobile/android/app/build.gradle.kts +++ b/tooling/cli/templates/mobile/android/app/build.gradle.kts @@ -1,4 +1,5 @@ import java.util.Properties +import java.io.FileInputStream plugins { id("com.android.application") @@ -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()) { @@ -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" @@ -45,6 +63,7 @@ android { .plus(getDefaultProguardFile("proguard-android-optimize.txt")) .toList().toTypedArray() ) + signingConfig = signingConfigs.getByName("release") } } kotlinOptions { diff --git a/tooling/cli/templates/mobile/android/keystore.properties.dummy b/tooling/cli/templates/mobile/android/keystore.properties.dummy new file mode 100644 index 000000000000..e31542aede8f --- /dev/null +++ b/tooling/cli/templates/mobile/android/keystore.properties.dummy @@ -0,0 +1,3 @@ +keyAlias=tauri-dummy +password=dummy-pwd +storeFile=./dummy-keystore.jks