import java.util.Properties import java.io.FileInputStream import java.io.FileOutputStream plugins { id("com.android.application") id("kotlin-android") // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. id("dev.flutter.flutter-gradle-plugin") // Google Services (FCM) id("com.google.gms.google-services") // Huawei AppGallery Connect (HMS Push) id("com.huawei.agconnect") } // ============================================ // Auto-increment version code on each build // ============================================ val versionPropertiesFile = rootProject.file("app/version.properties") val versionProperties = Properties() fun calculateNextVersionCode(): Int { if (versionPropertiesFile.exists()) { versionProperties.load(FileInputStream(versionPropertiesFile)) } val currentCode = versionProperties.getProperty("VERSION_CODE", "0").toInt() val newCode = currentCode + 1 versionProperties.setProperty("VERSION_CODE", newCode.toString()) versionProperties.store(FileOutputStream(versionPropertiesFile), "Auto-generated version code - DO NOT EDIT MANUALLY") return newCode } val autoVersionCode = calculateNextVersionCode() // Version name: major.minor.patch (from pubspec.yaml) + build number // Example: 1.0.0.42 fun getAutoVersionName(): String { val flutterVersionName = flutter.versionName return "$flutterVersionName.$autoVersionCode" } android { namespace = "com.iagent.it0_app" compileSdk = flutter.compileSdkVersion ndkVersion = flutter.ndkVersion compileOptions { isCoreLibraryDesugaringEnabled = true sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = JavaVersion.VERSION_17.toString() } defaultConfig { applicationId = "com.iagent.it0_app" minSdk = flutter.minSdkVersion targetSdk = flutter.targetSdkVersion versionCode = autoVersionCode versionName = getAutoVersionName() // OEM push credentials injected as BuildConfig fields. // Set these in local.properties or CI environment variables. val localProps = Properties().also { p -> rootProject.file("local.properties").takeIf { it.exists() }?.let { p.load(FileInputStream(it)) } } buildConfigField("String", "MI_APP_ID", "\"${localProps.getProperty("MI_APP_ID", "")}\"") buildConfigField("String", "MI_APP_KEY", "\"${localProps.getProperty("MI_APP_KEY", "")}\"") buildConfigField("String", "OPPO_APP_KEY", "\"${localProps.getProperty("OPPO_APP_KEY", "")}\"") buildConfigField("String", "OPPO_APP_SECRET", "\"${localProps.getProperty("OPPO_APP_SECRET", "")}\"") } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig = signingConfigs.getByName("debug") isMinifyEnabled = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } } buildFeatures { buildConfig = true } } dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4") // ── OEM Push SDKs ────────────────────────────────────────────────────────── // AARs placed in android/app/libs/ (downloaded from each OEM's developer portal). // Xiaomi Push SDK: https://dev.mi.com/distribute/doc/details?pId=1479 // OPPO HeytapPush SDK: https://open.oppomobile.com/new/developmentDoc/info?id=11212 // vivo Push SDK: https://dev.vivo.com.cn/documentCenter/doc/332 implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar")))) } flutter { source = "../.." }