LifeMate — Personal, Family & Learning Companion
feat/local-signing-preflight
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
| 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 | // Never-distributed synthetic acceptance identity, not a replacement user APK. |
| 16 | val personalRecoveryQa = providers.gradleProperty("lifeguidePersonalRecoveryQa").orNull == "true" |
| 17 | val requestedTasks = gradle.startParameter.taskNames.map { it.substringAfterLast(':').lowercase() } |
| 18 | val assembling = requestedTasks.any { it.startsWith("assemble") || it.startsWith("bundle") } |
| 19 | val decodedDefines = providers.gradleProperty("dart-defines").orNull.orEmpty() |
| 20 | .split(',').filter { it.isNotBlank() }.map { String(Base64.getDecoder().decode(it)) } |
| 21 | val standaloneDefine = decodedDefines.contains("LIFEGUIDE_STANDALONE=true") |
| 22 | val recoveryDefine = decodedDefines.contains("LIFEGUIDE_PERSONAL_RECOVERY_QA=true") |
| 23 | val dartTarget = providers.gradleProperty("target").orNull.orEmpty().replace('\\', '/') |
| 24 | val recoveryTarget = dartTarget.endsWith("tool/personal_recovery_fixture.dart") |
| 25 | if (personalRecoveryQa && !devicePlannerOnly) { |
| 26 | throw GradleException("Synthetic recovery QA requires the isolated device planner.") |
| 27 | } |
| 28 | // Gradle aliases such as build/installDebug/packageDebug may execute assembly |
| 29 | // without an assemble* task in taskNames. Refuse aliases for this QA identity. |
| 30 | if (personalRecoveryQa && (requestedTasks.isEmpty() || requestedTasks.any { it != "assembledebug" })) { |
| 31 | throw GradleException("Synthetic recovery QA is a debug-only initial edition; request assembleDebug explicitly.") |
| 32 | } |
| 33 | if (personalRecoveryQa && !(standaloneDefine && recoveryDefine && recoveryTarget)) { |
| 34 | throw GradleException("Synthetic recovery QA requires its matching defines and entry point.") |
| 35 | } |
| 36 | if (!personalRecoveryQa && (recoveryDefine || recoveryTarget)) { |
| 37 | throw GradleException("Recovery fixtures cannot be packaged as a user application.") |
| 38 | } |
| 39 | if (devicePlannerOnly) { |
| 40 | if (requestedTasks.any { it.contains("release") || it.contains("profile") || it == "assemble" || it == "bundle" }) { |
| 41 | throw GradleException("The independent device planner is a debug-only initial edition.") |
| 42 | } |
| 43 | if (assembling && !standaloneDefine) { |
| 44 | throw GradleException("Device planner builds require the matching LIFEGUIDE_STANDALONE define.") |
| 45 | } |
| 46 | if (assembling && !(dartTarget.endsWith("lib/standalone_main.dart") || dartTarget.endsWith("tool/standalone_acceptance_fixture.dart") || (personalRecoveryQa && recoveryTarget))) { |
| 47 | throw GradleException("The device edition requires its isolated Dart entry point.") |
| 48 | } |
| 49 | } else if (assembling && standaloneDefine) { |
| 50 | throw GradleException("Standalone Dart cannot be packaged as the online application.") |
| 51 | } |
| 52 | val releaseEnvironment = listOf("LIFEGUIDE_KEYSTORE_PATH", "LIFEGUIDE_KEYSTORE_PASSWORD", "LIFEGUIDE_KEY_ALIAS", "LIFEGUIDE_KEY_PASSWORD") |
| 53 | val signingValues = releaseEnvironment.associateWith { System.getenv(it) } |
| 54 | if (releaseRequested) { |
| 55 | val missing = signingValues.filterValues { it.isNullOrBlank() }.keys |
| 56 | if (missing.isNotEmpty()) throw GradleException("Release signing requires environment variables: ${missing.joinToString()}") |
| 57 | val keyFile = file(signingValues.getValue("LIFEGUIDE_KEYSTORE_PATH")!!) |
| 58 | val releaseAlias = signingValues.getValue("LIFEGUIDE_KEY_ALIAS")!! |
| 59 | if (!keyFile.isFile || keyFile.name.equals("debug.keystore", ignoreCase = true) || releaseAlias.equals("androiddebugkey", ignoreCase = true)) { |
| 60 | throw GradleException("A real owner-supplied release keystore is required.") |
| 61 | } |
| 62 | val keyStore = try { |
| 63 | KeyStore.getInstance(keyFile, signingValues.getValue("LIFEGUIDE_KEYSTORE_PASSWORD")!!.toCharArray()) |
| 64 | } catch (_: Exception) { |
| 65 | throw GradleException("The owner-supplied release keystore could not be opened.") |
| 66 | } |
| 67 | val certificate = keyStore.getCertificate(releaseAlias) as? X509Certificate |
| 68 | if (!keyStore.isKeyEntry(releaseAlias) || certificate == null) { |
| 69 | throw GradleException("The release signing alias must contain a private key and certificate.") |
| 70 | } |
| 71 | if (LdapName(certificate.subjectX500Principal.name).rdns.any { it.type.equals("CN", ignoreCase = true) && it.value.toString().equals("Android Debug", ignoreCase = true) }) { |
| 72 | throw GradleException("Android debug certificates are forbidden for release signing.") |
| 73 | } |
| 74 | val defines = providers.gradleProperty("dart-defines").orNull.orEmpty().split(',').filter { it.isNotBlank() } |
| 75 | if (defines.any { String(Base64.getDecoder().decode(it)).startsWith("LIFEGUIDE_DEBUG_CA_BASE64=") && String(Base64.getDecoder().decode(it)).substringAfter('=').isNotEmpty() }) { |
| 76 | throw GradleException("Development CA input is forbidden in release builds.") |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | android { |
| 81 | namespace = "ir.lifeguide.app" |
| 82 | compileSdk = flutter.compileSdkVersion |
| 83 | ndkVersion = flutter.ndkVersion |
| 84 | buildFeatures { buildConfig = true } |
| 85 | if (devicePlannerOnly) { |
| 86 | sourceSets.getByName("debug").manifest.srcFile(if (personalRecoveryQa) "src/recoveryQa/AndroidManifest.xml" else "src/devicePlanner/AndroidManifest.xml") |
| 87 | } |
| 88 | |
| 89 | compileOptions { |
| 90 | sourceCompatibility = JavaVersion.VERSION_17 |
| 91 | targetCompatibility = JavaVersion.VERSION_17 |
| 92 | } |
| 93 | |
| 94 | defaultConfig { |
| 95 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). |
| 96 | applicationId = when { |
| 97 | personalRecoveryQa -> "ir.lifeguide.app.personal" |
| 98 | devicePlannerOnly -> "ir.lifeguide.app.device" |
| 99 | else -> "ir.lifeguide.app" |
| 100 | } |
| 101 | buildConfigField("boolean", "DEVICE_PLANNER_ONLY", devicePlannerOnly.toString()) |
| 102 | buildConfigField("boolean", "PERSONAL_RECOVERY_QA", personalRecoveryQa.toString()) |
| 103 | // You can update the following values to match your application needs. |
| 104 | // For more information, see: https://flutter.dev/to/review-gradle-config. |
| 105 | minSdk = flutter.minSdkVersion |
| 106 | targetSdk = flutter.targetSdkVersion |
| 107 | // Uses the version code from pubspec.yaml. When using split APKs, 1000 * ABI_VERSION |
| 108 | // is added automatically by Flutter. (https://developer.android.com/studio/build/configure-apk-splits#configure-APK-versions) |
| 109 | // You can force using the value of versionCode by specifying the `-P force-version-code-ignoring-abi=true` |
| 110 | // flag during build. |
| 111 | versionCode = flutter.versionCode |
| 112 | versionName = flutter.versionName |
| 113 | if (personalRecoveryQa && (flutter.versionCode !in 10..11 || flutter.versionName != "0.7.2-recovery-qa.${flutter.versionCode}")) { |
| 114 | throw GradleException("Only private synthetic recovery QA versions 10 and 11 are allowed.") |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | signingConfigs { |
| 119 | create("release") { |
| 120 | signingValues["LIFEGUIDE_KEYSTORE_PATH"]?.let { storeFile = file(it) } |
| 121 | storePassword = signingValues["LIFEGUIDE_KEYSTORE_PASSWORD"] |
| 122 | keyAlias = signingValues["LIFEGUIDE_KEY_ALIAS"] |
| 123 | keyPassword = signingValues["LIFEGUIDE_KEY_PASSWORD"] |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | buildTypes { |
| 128 | release { |
| 129 | signingConfig = signingConfigs.getByName("release") |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | kotlin { |
| 135 | compilerOptions { |
| 136 | jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | flutter { |
| 141 | source = "../.." |
| 142 | } |