LifeMate — Personal, Family & Learning Companion

fix/personal-upgrade-delivery-guard
chore/phase1-repository-cleanup deploy/stable-web-apk deployment-static design/mobile-accessibility-v2 design/mobile-navigation-review docs/child-education-access-decision docs/offline-data-rescue-options docs/owner-guide-and-delivery-plan docs/phase1-policy-options docs/public-review-live-2026-10-15 feat/aparat-learning-library feat/child-device-safety feat/child-identity-schema feat/flutter-mobile-navigation feat/learning-content-operations feat/local-signing-preflight feat/online-family-stage0 feat/personal-encrypted-recovery feat/private-planner-series-api feat/public-review-page feat/standalone-weekly-planner feat/weekly-planner-android final-feature-1/iran-family-school fix/auth-abuse-expiry-safety fix/auth-expiry-after-lock fix/backend-request-safety fix/lifeguide-bootstrap-naming-ci fix/lifeguide-pages-qa-base-preflight fix/lifeguide-qa-pages-env-deployment fix/local-task-persistence fix/managed-child-session-boundary fix/personal-jalali-dates fix/personal-notification-controls fix/personal-upgrade-delivery-guard fix/sms-approval-gates fix/study-duration-display infra/cloudflare-neon-migration infra/lifeguide-cloudflare-qa infra/lifeguide-github-pages-qa infra/lifeguide-supabase-qa main phase-1/foundation-completion phase-2/product-foundation-identity phase-3/planner-school-family-core phase-4/ai-learning-wellbeing phase-5/hardening-observability-release test/android-reminder-acceptance test/personal-notification-settings test/personal-recovery-acceptance test/role-entry-apk
kts 116 lines 5.85 KB
Raw
1 import java.util.Base64
2 import java.security.KeyStore
3 import java.security.cert.X509Certificate
4 import javax.naming.ldap.LdapName
5
6 plugins {
7 id("com.android.application")
8 // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
9 id("dev.flutter.flutter-gradle-plugin")
10 }
11
12 val releaseRequested = gradle.startParameter.taskNames.any { it.contains("release", ignoreCase = true) }
13 // A separate, debug-only device edition. The published online identity stays fixed.
14 val devicePlannerOnly = providers.gradleProperty("lifeguideDevicePlanner").orNull == "true"
15 val requestedTasks = gradle.startParameter.taskNames.map { it.substringAfterLast(':').lowercase() }
16 val assembling = requestedTasks.any { it.startsWith("assemble") || it.startsWith("bundle") }
17 val decodedDefines = providers.gradleProperty("dart-defines").orNull.orEmpty()
18 .split(',').filter { it.isNotBlank() }.map { String(Base64.getDecoder().decode(it)) }
19 val standaloneDefine = decodedDefines.contains("LIFEGUIDE_STANDALONE=true")
20 if (devicePlannerOnly) {
21 if (requestedTasks.any { it.contains("release") || it.contains("profile") || it == "assemble" || it == "bundle" }) {
22 throw GradleException("The independent device planner is a debug-only initial edition.")
23 }
24 if (assembling && !standaloneDefine) {
25 throw GradleException("Device planner builds require the matching LIFEGUIDE_STANDALONE define.")
26 }
27 val target = providers.gradleProperty("target").orNull.orEmpty().replace('\\', '/')
28 if (assembling && !(target.endsWith("lib/standalone_main.dart") || target.endsWith("tool/standalone_acceptance_fixture.dart"))) {
29 throw GradleException("The device edition requires its isolated Dart entry point.")
30 }
31 } else if (assembling && standaloneDefine) {
32 throw GradleException("Standalone Dart cannot be packaged as the online application.")
33 }
34 val releaseEnvironment = listOf("LIFEGUIDE_KEYSTORE_PATH", "LIFEGUIDE_KEYSTORE_PASSWORD", "LIFEGUIDE_KEY_ALIAS", "LIFEGUIDE_KEY_PASSWORD")
35 val signingValues = releaseEnvironment.associateWith { System.getenv(it) }
36 if (releaseRequested) {
37 val missing = signingValues.filterValues { it.isNullOrBlank() }.keys
38 if (missing.isNotEmpty()) throw GradleException("Release signing requires environment variables: ${missing.joinToString()}")
39 val keyFile = file(signingValues.getValue("LIFEGUIDE_KEYSTORE_PATH")!!)
40 val releaseAlias = signingValues.getValue("LIFEGUIDE_KEY_ALIAS")!!
41 if (!keyFile.isFile || keyFile.name.equals("debug.keystore", ignoreCase = true) || releaseAlias.equals("androiddebugkey", ignoreCase = true)) {
42 throw GradleException("A real owner-supplied release keystore is required.")
43 }
44 val keyStore = try {
45 KeyStore.getInstance(keyFile, signingValues.getValue("LIFEGUIDE_KEYSTORE_PASSWORD")!!.toCharArray())
46 } catch (_: Exception) {
47 throw GradleException("The owner-supplied release keystore could not be opened.")
48 }
49 val certificate = keyStore.getCertificate(releaseAlias) as? X509Certificate
50 if (!keyStore.isKeyEntry(releaseAlias) || certificate == null) {
51 throw GradleException("The release signing alias must contain a private key and certificate.")
52 }
53 if (LdapName(certificate.subjectX500Principal.name).rdns.any { it.type.equals("CN", ignoreCase = true) && it.value.toString().equals("Android Debug", ignoreCase = true) }) {
54 throw GradleException("Android debug certificates are forbidden for release signing.")
55 }
56 val defines = providers.gradleProperty("dart-defines").orNull.orEmpty().split(',').filter { it.isNotBlank() }
57 if (defines.any { String(Base64.getDecoder().decode(it)).startsWith("LIFEGUIDE_DEBUG_CA_BASE64=") && String(Base64.getDecoder().decode(it)).substringAfter('=').isNotEmpty() }) {
58 throw GradleException("Development CA input is forbidden in release builds.")
59 }
60 }
61
62 android {
63 namespace = "ir.lifeguide.app"
64 compileSdk = flutter.compileSdkVersion
65 ndkVersion = flutter.ndkVersion
66 buildFeatures { buildConfig = true }
67 if (devicePlannerOnly) {
68 sourceSets.getByName("debug").manifest.srcFile("src/devicePlanner/AndroidManifest.xml")
69 }
70
71 compileOptions {
72 sourceCompatibility = JavaVersion.VERSION_17
73 targetCompatibility = JavaVersion.VERSION_17
74 }
75
76 defaultConfig {
77 // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
78 applicationId = if (devicePlannerOnly) "ir.lifeguide.app.device" else "ir.lifeguide.app"
79 buildConfigField("boolean", "DEVICE_PLANNER_ONLY", devicePlannerOnly.toString())
80 // You can update the following values to match your application needs.
81 // For more information, see: https://flutter.dev/to/review-gradle-config.
82 minSdk = flutter.minSdkVersion
83 targetSdk = flutter.targetSdkVersion
84 // Uses the version code from pubspec.yaml. When using split APKs, 1000 * ABI_VERSION
85 // is added automatically by Flutter. (https://developer.android.com/studio/build/configure-apk-splits#configure-APK-versions)
86 // You can force using the value of versionCode by specifying the `-P force-version-code-ignoring-abi=true`
87 // flag during build.
88 versionCode = flutter.versionCode
89 versionName = flutter.versionName
90 }
91
92 signingConfigs {
93 create("release") {
94 signingValues["LIFEGUIDE_KEYSTORE_PATH"]?.let { storeFile = file(it) }
95 storePassword = signingValues["LIFEGUIDE_KEYSTORE_PASSWORD"]
96 keyAlias = signingValues["LIFEGUIDE_KEY_ALIAS"]
97 keyPassword = signingValues["LIFEGUIDE_KEY_PASSWORD"]
98 }
99 }
100
101 buildTypes {
102 release {
103 signingConfig = signingConfigs.getByName("release")
104 }
105 }
106 }
107
108 kotlin {
109 compilerOptions {
110 jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
111 }
112 }
113
114 flutter {
115 source = "../.."
116 }