Files
Incido/app/build.gradle.kts
T
2026-08-20 07:31:05 +12:00

202 lines
8.1 KiB
Kotlin

// :app — Android application entry point. Hosts MainActivity and the
// application manifest, including the launcher icon and theme.
//
// Version scheme (v0.3.0.0 onwards):
// versionName = "MAJOR.MINOR.MAINTENANCE.EMERGENCY"
// - MAJOR: large breaking redesigns (rare in v0.x)
// - MINOR: normal feature releases
// - MAINTENANCE: bug fixes / refactors on a given MINOR
// - EMERGENCY: 0 in normal releases; non-zero only for hotfixes
// shipped out-of-band (e.g. v0.2.0.1 — search-icon fix)
// versionCode: monotonic int. Always +1 per release.
//
// The validator below fails the build if versionName doesn't match the
// required dotted format, so we can't regress the scheme by accident.
import java.util.Properties
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kotlinCompose)
}
android {
namespace = "org.incido.app"
compileSdk = 35
defaultConfig {
applicationId = "org.incido.app"
minSdk = 26
targetSdk = 35
// v0.3.6.3: Local-dev DX — make the missing-keystore failure
// mode actionable.
// - signingConfigs.release now throws GradleException at
// config time when keystore/release.jks is missing, with
// the exact keytool incantation from keystore/README.md
// in the error message. Previously the signing config
// silently fell through with no storeFile, and packageRelease
// failed much later with the cryptic "SigningConfig release
// is missing required property storeFile" — leaving devs
// guessing at the cause.
// - .gitea/workflows/release.yml already mints the keystore
// on release runners (since v0.3.6.2), so CI is unaffected.
// - No app/Compose code changes.
// - versionCode monotonic +1 from v0.3.6.2 (29).
versionCode = 30
versionName = "0.3.6.3"
}
// --- Signing ---
// v0.3.6.3: Fail fast (at config time) with an actionable error
// when keystore/release.jks is missing, rather than silently
// letting packageRelease die later with the cryptic "SigningConfig
// release is missing required property storeFile". CI (see
// .gitea/workflows/release.yml) already mints the keystore before
// assembleRelease (since v0.3.6.2), so this branch never fires on
// a release runner — only on a fresh local clone.
signingConfigs {
create("release") {
val keystoreFilePath = rootProject.file("keystore/release.jks")
if (!keystoreFilePath.exists()) {
throw GradleException(
"Missing ${keystoreFilePath.absolutePath}.\n" +
"Generate the dev keystore documented in " +
"keystore/README.md:\n" +
" keytool -genkey -noprompt -v \\\n" +
" -keystore keystore/release.jks \\\n" +
" -keyalg RSA -keysize 2048 -validity 10000 \\\n" +
" -alias incido \\\n" +
" -storepass incido_dev_keystore \\\n" +
" -keypass incido_dev_keystore \\\n" +
" -dname \"CN=Incido Dev, OU=Local, O=Incido, " +
"L=Local, ST=Local, C=NZ\""
)
}
storeFile = keystoreFilePath
storePassword = "incido_dev_keystore"
keyAlias = "incido"
keyPassword = "incido_dev_keystore"
}
}
buildTypes {
debug {
isMinifyEnabled = false
}
release {
isMinifyEnabled = false // TODO(v0.3.0.0+): enable R8
signingConfig = signingConfigs.getByName("release")
}
}
buildFeatures {
compose = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
// v0.3.6.0: ship version-stamped APKs at the repo root for every
// release (e.g. `Incido-0.3.6.0-debug.apk`, `Incido-0.3.6.0-release.apk`).
// See Incido Development Plan §11 for the full release build
// procedure.
//
// Rather than mutating each variant's `outputFileName` (which trips over
// Kotlin/Gradle DSL overload ambiguities in AGP 8.x — the legacy
// `applicationVariants.outputs.all { ... }` lambda resolution clashes
// with `Iterable<T>.all(predicate: (T) -> Boolean)` and the modern
// `androidComponents.onVariants` API doesn't expose `outputFileName` as
// a settable property on its outputs), we just register a copy task
// that runs after both `assembleDebug` and `assembleRelease` and drops
// the built APKs at the project root with the right names.
//
// `copyReleaseApks` is registered as a `dependsOn` of `assembleRelease`
// so `./gradlew assembleRelease` is enough to get both files at the
// repo root in one command.
val copyReleaseApks = tasks.register("copyReleaseApks") {
group = "build"
description = "Copies debug + release APKs to the repo root, " +
"stamped with the current versionName " +
"(e.g. Incido-0.3.6.3-debug.apk, Incido-0.3.6.3-release.apk). " +
"See Incido Development Plan §11."
dependsOn("assembleDebug", "assembleRelease")
doLast {
val versionName = android.defaultConfig.versionName
val rootDir = rootProject.projectDir
val debugSrc = file("$buildDir/outputs/apk/debug/app-debug.apk")
val releaseSrc = file("$buildDir/outputs/apk/release/app-release.apk")
val debugDest = file("$rootDir/Incido-${versionName}-debug.apk")
val releaseDest = file("$rootDir/Incido-${versionName}-release.apk")
if (debugSrc.exists()) {
debugSrc.copyTo(debugDest, overwrite = true)
logger.lifecycle("Copied: ${debugDest.absolutePath}")
} else {
logger.warn("Debug APK not found at ${debugSrc.absolutePath}")
}
if (releaseSrc.exists()) {
releaseSrc.copyTo(releaseDest, overwrite = true)
logger.lifecycle("Copied: ${releaseDest.absolutePath}")
} else {
logger.warn("Release APK not found at ${releaseSrc.absolutePath}")
}
}
}
// Make `assembleRelease` finalize with `copyReleaseApks` so a single
// `./gradlew assembleRelease` produces both root-level APKs. Using
// `finalizedBy` (not `dependsOn`) avoids a circular dependency:
// `copyReleaseApks` already `dependsOn` `assembleRelease`.
afterEvaluate {
tasks.findByName("assembleRelease")?.finalizedBy(copyReleaseApks)
}
dependencies {
implementation(project(":composeApp"))
// v0.3.1.0: MainActivity needs the NoteRepository type to hand it
// through to IncidoApp (used by the editor's full-screen image
// viewer + the list card thumbnails). It's the *interface* in
// :core:domain, not the impl, so this stays clean of ObjectBox.
implementation(project(":core:domain"))
implementation(libs.androidx.core.ktx)
implementation(libs.kotlinx.coroutines.android)
// v0.3.2.0: MainActivity now extends FragmentActivity so the
// BiometricPrompt has a Fragment-based host.
implementation(libs.androidx.fragment.ktx)
val composeBom = platform(libs.composeBom)
implementation(composeBom)
implementation(libs.androidx.activity.compose)
implementation(libs.compose.ui)
implementation(libs.compose.material3)
}
// --- Version-name scheme validator ---
//
// MAJOR.MINOR.MAINTENANCE.EMERGENCY — exactly four dotted integers.
// Fails fast so we can't accidentally publish a "0.3" again.
val versionScheme = Regex("""^\d+\.\d+\.\d+\.\d+$""")
gradle.taskGraph.whenReady {
val vn = android.defaultConfig.versionName
if (vn != null && !versionScheme.matches(vn)) {
throw GradleException(
"app versionName = \"$vn\" doesn't match the required " +
"MAJOR.MINOR.MAINTENANCE.EMERGENCY scheme (e.g. 0.3.0.0). " +
"Update app/build.gradle.kts."
)
}
}