From b8c9f88cfda579a0aeb30d5259caf5767e708d78 Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Thu, 18 Jun 2026 12:40:51 +0200 Subject: [PATCH] feat: add .env support for local release builds --- clients/android/.env.template | 9 ++++++++ clients/android/.gitignore | 4 ++++ clients/android/app/build.gradle.kts | 32 +++++++++++++++++++++------- 3 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 clients/android/.env.template diff --git a/clients/android/.env.template b/clients/android/.env.template new file mode 100644 index 0000000..c3ce55c --- /dev/null +++ b/clients/android/.env.template @@ -0,0 +1,9 @@ +# Punktfunk Android Release Secrets +# Copy this file to .env and fill in the values. +# DO NOT COMMIT THE .env FILE! + +RELEASE_KEYSTORE_FILE=../punktfunk-release.jks +RELEASE_KEYSTORE_PASSWORD= +RELEASE_KEY_ALIAS=punktfunk-key +RELEASE_KEY_PASSWORD= +VERSION_CODE=1 diff --git a/clients/android/.gitignore b/clients/android/.gitignore index d4ef852..7412237 100644 --- a/clients/android/.gitignore +++ b/clients/android/.gitignore @@ -9,3 +9,7 @@ captures/ # Native libraries produced by cargo-ndk — regenerated by the :kit cargoNdk* tasks. **/src/main/jniLibs/ + +# Secrets +.env +*.jks diff --git a/clients/android/app/build.gradle.kts b/clients/android/app/build.gradle.kts index 910b205..17880a2 100644 --- a/clients/android/app/build.gradle.kts +++ b/clients/android/app/build.gradle.kts @@ -1,5 +1,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import java.util.Properties + plugins { id("com.android.application") // AGP 9 built-in Kotlin: NO org.jetbrains.kotlin.android. The Compose compiler plugin is @@ -12,23 +14,37 @@ android { compileSdk = 37 // Android 17 — required by androidx.core 1.19.0; targetSdk stays 36 for now. defaultConfig { + // Load from .env if it exists (local dev), otherwise from System.getenv (CI) + val envFile = project.rootProject.file(".env") + val props = Properties() + if (envFile.exists()) { + envFile.inputStream().use { props.load(it) } + } + applicationId = "io.unom.punktfunk" minSdk = 31 targetSdk = 36 - versionCode = System.getenv("VERSION_CODE")?.toInt() ?: 1 + val vCode = (props.getProperty("VERSION_CODE") ?: System.getenv("VERSION_CODE")) + versionCode = vCode?.toInt() ?: 1 versionName = "0.0.2" // bumped for first Play Store release ndk { abiFilters += listOf("arm64-v8a", "x86_64") } } signingConfigs { create("release") { - // These are provided by CI secrets as environment variables - val keystoreFile = System.getenv("RELEASE_KEYSTORE_FILE") - if (keystoreFile != null) { - storeFile = file(keystoreFile) - storePassword = System.getenv("RELEASE_KEYSTORE_PASSWORD") - keyAlias = System.getenv("RELEASE_KEY_ALIAS") - keyPassword = System.getenv("RELEASE_KEY_PASSWORD") + // Load from .env if it exists (local dev), otherwise from System.getenv (CI) + val envFile = project.rootProject.file(".env") + val props = Properties() + if (envFile.exists()) { + envFile.inputStream().use { props.load(it) } + } + + val ksFile = props.getProperty("RELEASE_KEYSTORE_FILE") ?: System.getenv("RELEASE_KEYSTORE_FILE") + if (ksFile != null) { + storeFile = file(ksFile) + storePassword = props.getProperty("RELEASE_KEYSTORE_PASSWORD") ?: System.getenv("RELEASE_KEYSTORE_PASSWORD") + keyAlias = props.getProperty("RELEASE_KEY_ALIAS") ?: System.getenv("RELEASE_KEY_ALIAS") + keyPassword = props.getProperty("RELEASE_KEY_PASSWORD") ?: System.getenv("RELEASE_KEY_PASSWORD") } } }