diff --git a/.gitignore b/.gitignore index 34032b8..63f02e6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ __pycache__/ node_modules/ worker-donation/wrangler.toml .letta/ +*.keystore diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index f325564..8002907 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -1,4 +1,5 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import java.util.Properties plugins { alias(libs.plugins.kotlin.multiplatform) @@ -11,6 +12,40 @@ plugins { id("com.diffplug.spotless") version "8.2.1" } +val localProperties = + Properties().apply { + val file = rootProject.file("local.properties") + if (file.isFile) { + file.inputStream().use(::load) + } + } + +fun signingProperty(name: String): String? = + providers.gradleProperty(name).orNull + ?: providers.environmentVariable(name).orNull + ?: localProperties.getProperty(name) + +val derakkumaKeystoreFile = rootProject.file("derakkuma.keystore") +val derakkumaKeystorePassword = signingProperty("KEYSTORE_PASSWORD") +val derakkumaKeyAlias = signingProperty("KEY_ALIAS") ?: "derakkuma" +val derakkumaKeyPassword = signingProperty("KEY_PASSWORD") ?: derakkumaKeystorePassword +val requestedReleaseBuild = + gradle.startParameter.taskNames.any { taskName -> + taskName.contains("Release", ignoreCase = true) + } + +if (requestedReleaseBuild) { + require(derakkumaKeystoreFile.isFile) { + "Release builds must be signed with ${derakkumaKeystoreFile.path}" + } + require(!derakkumaKeystorePassword.isNullOrBlank()) { + "Set KEYSTORE_PASSWORD in local.properties, Gradle properties, or the environment" + } + require(!derakkumaKeyPassword.isNullOrBlank()) { + "Set KEY_PASSWORD in local.properties, Gradle properties, or the environment" + } +} + spotless { kotlin { target("**/*.kt") @@ -106,6 +141,15 @@ android { namespace = "com.derakkuma" compileSdk = 36 + signingConfigs { + create("release") { + storeFile = derakkumaKeystoreFile + storePassword = derakkumaKeystorePassword.orEmpty() + keyAlias = derakkumaKeyAlias + keyPassword = derakkumaKeyPassword.orEmpty() + } + } + defaultConfig { applicationId = "com.derakkuma" minSdk = 26 @@ -122,6 +166,12 @@ android { buildFeatures { compose = true } + + buildTypes { + release { + signingConfig = signingConfigs.getByName("release") + } + } } sqldelight {