Milestone M3 task 1 (DESKTOP_PHASE_PLAN §5): move UserSettings +
SettingsRepository into a plain kotlin("jvm") module so the desktop
build reads/writes the SAME preferences keys and .preferences_pb format
the phone uses. Package name org.incido.compose.data.settings kept, so
the Android diff is file moves + one constructor change.
Seam: SettingsRepository now takes an injected DataStore<Preferences>.
Android supplies the preferencesDataStore(name = "incido_settings")
Context-extension store (new AndroidSettingsStore.kt, moved verbatim);
desktop builds it with PreferenceDataStoreFactory.create(
corruptionHandler = ReplaceFileCorruptionHandler, produceFile) — the
Phase-0 API delta (no Context extension on the multiplatform core
artifact). snapshot() keeps runBlocking for startup-only use.
DesktopContainer grows settingsRepository first, mirroring AppContainer
construction order ahead of M3's cipher install. dynamic_color /
use_biometric / block_screenshots keys ride along but have no desktop
UI — hidden, not faked (M3 exit rule).
Verified: ./gradlew assembleDebug (green; :app needed :core:settings on
its classpath — MainActivity reads userSettingsFlow, same pattern as
:core:domain) + ./gradlew :desktopApp:run --args="--data-dir
/tmp/incido-desktop-smoke --self-test --exit-after 6" (RENDER/SELFTEST
sequence intact) + ./gradlew :core:data-jvm:smoke (green).
234 lines
9.9 KiB
Kotlin
234 lines
9.9 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.4.1.1: EMERGENCY hotfix — two editor regressions shipped
|
||
// in v0.4.1.0. (1) Saving a note landed it in Drafts: the save
|
||
// path published the note but left UiState.existing.isDraft =
|
||
// true, so the editor's dispose-time flushDraft() immediately
|
||
// re-persisted it as a draft; the state now adopts the
|
||
// published row (isDraft = false), letting persistDraftNow()'s
|
||
// already-published guard make the flush a no-op. (2) Enter on
|
||
// a shopping-list Price field fell through to system focus
|
||
// traversal and wrapped the cursor back to the Title; it now
|
||
// wires KeyboardActions(onNext = onAddAfter) like the Product
|
||
// field — Enter adds a fresh row with the cursor in its
|
||
// Product box.
|
||
// - versionCode monotonic +1 from v0.4.1.0 (36).
|
||
// v0.4.2.0: FEATURE release — voice notes. New note type (mic
|
||
// button on the editor's bottom toolbar toggles it; the toolbar
|
||
// is reordered Photo · Voice · Attach · Tasks · Shopping list
|
||
// with the hashtag button pushed flush right): a record /
|
||
// re-record card plus a MediaPlayer-backed player bar (play/
|
||
// pause, seek, elapsed/total) pinned at the top of the body,
|
||
// with a Download action copying the take to the system
|
||
// Downloads folder (share-sheet fallback on API 26–28). Takes
|
||
// record as Opus in Ogg (.opus, 32 kbps, mono, 48 kHz) on
|
||
// API 29+; API 26–28 keeps the AAC/MP4 fallback. Audio
|
||
// rides the ordinary attachment pipeline — encrypted at rest,
|
||
// in backups, survives type changes. RECORD_AUDIO permission
|
||
// added; zero new dependencies (framework MediaRecorder /
|
||
// MediaPlayer only).
|
||
// - versionCode monotonic +1 from v0.4.1.1 (37).
|
||
versionCode = 38
|
||
versionName = "0.4.2.0"
|
||
}
|
||
|
||
// --- Signing ---
|
||
// The release signing config is declared even when the keystore is absent;
|
||
// the existence check is deferred to assembleRelease execution time so that
|
||
// assembleDebug (which doesn't need the keystore) runs cleanly on a fresh
|
||
// clone. CI always mints the keystore before calling assembleRelease, so
|
||
// this branch never fires in the normal workflow.
|
||
signingConfigs {
|
||
create("release") {
|
||
storeFile = rootProject.file("keystore/release.jks")
|
||
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")
|
||
}
|
||
}
|
||
|
||
// Fail fast with an actionable message only when assembleRelease actually
|
||
// runs and the keystore is missing — not during project configuration.
|
||
tasks.register("validateReleaseKeystore") {
|
||
group = "build"
|
||
description = "Validates that keystore/release.jks exists before assembleRelease runs"
|
||
doFirst {
|
||
val f = rootProject.file("keystore/release.jks")
|
||
if (!f.exists()) {
|
||
throw GradleException(
|
||
"Missing ${f.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\""
|
||
)
|
||
}
|
||
}
|
||
}
|
||
buildFeatures {
|
||
compose = true
|
||
}
|
||
|
||
compileOptions {
|
||
sourceCompatibility = JavaVersion.VERSION_17
|
||
targetCompatibility = JavaVersion.VERSION_17
|
||
}
|
||
|
||
kotlin {
|
||
jvmToolchain(17)
|
||
}
|
||
|
||
packaging {
|
||
resources {
|
||
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||
}
|
||
}
|
||
}
|
||
|
||
// Wire the keystore validator after Android has created the release task.
|
||
// Looking the task up before configuration completes makes the build fail
|
||
// for unrelated compile/debug tasks as well.
|
||
afterEvaluate {
|
||
tasks.findByName("assembleRelease")?.dependsOn("validateReleaseKeystore")
|
||
}
|
||
|
||
// 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 the debug and release builds and drops the built APKs
|
||
// at the project root with the right names. The release task is attached
|
||
// as a finalizer below, so the copy task must not depend on it directly.
|
||
//
|
||
// `copyReleaseApks` runs as a finalizer 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."
|
||
// assembleRelease invokes this task as a finalizer; depending on
|
||
// assembleRelease here would create a task graph cycle.
|
||
dependsOn("assembleDebug")
|
||
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. The copy
|
||
// task depends on assembleDebug, avoiding a task graph cycle.
|
||
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"))
|
||
// Phase 1 (M3 task 1): same reason for SettingsRepository — MainActivity
|
||
// reads userSettingsFlow / snapshot() and its type moved with the class
|
||
// into the shared :core:settings module.
|
||
implementation(project(":core:settings"))
|
||
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."
|
||
)
|
||
}
|
||
} |