import java.io.FileOutputStream import java.text.SimpleDateFormat import java.util.Date import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream plugins { alias(libs.plugins.androidApplication) alias(libs.plugins.jetbrainsKotlinAndroid) alias(libs.plugins.googleServices) } val appVersionName = "9.6" val betaVersionName = "2.5" val isBetaBuild = (findProperty("betaBuild")?.toString()?.toBooleanStrictOrNull()) ?: false val useEmbeddedWebAssets = (findProperty("forceEmbeddedWebAssets")?.toString()?.toBooleanStrictOrNull()) ?: false val resolvedApplicationId = if (isBetaBuild) "com.gramiatechnologies.gramia.beta" else "com.gramiatechnologies.gramia" val resolvedVersionName = if (isBetaBuild) betaVersionName else appVersionName val resolvedAppLabel = if (isBetaBuild) "Gramia Beta" else "Gramia" val bundledWebBundleAssetsDir = layout.buildDirectory.dir("generated/bundled-webbundle-assets/main") val bundledWebBundleSourceDir = layout.projectDirectory.dir("src/main/assets") val bundledWebBundleVersionName = provider { val timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date()) "android-${resolvedVersionName}-bundled-$timestamp" } val generateBundledWebBundleAssets = tasks.register("generateBundledWebBundleAssets") { val outputDir = bundledWebBundleAssetsDir val sourceDir = bundledWebBundleSourceDir inputs.dir(sourceDir) outputs.dir(outputDir) doLast { val baseDir = outputDir.get().asFile.resolve("preloaded-webbundle/android") val zipFile = baseDir.resolve("latest.zip") val versionFile = baseDir.resolve("version.txt") if (baseDir.exists()) { baseDir.deleteRecursively() } baseDir.mkdirs() val sourceRoot = sourceDir.asFile FileOutputStream(zipFile).use { fileOutput -> ZipOutputStream(fileOutput).use { zipOutput -> sourceRoot.walkTopDown() .filter { it.isFile } .filterNot { it.name == ".DS_Store" || it.name.startsWith("._") } .filterNot { val relative = it.relativeTo(sourceRoot).invariantSeparatorsPath relative.startsWith("preloaded-webbundle/") } .forEach { file -> val relativePath = file.relativeTo(sourceRoot).invariantSeparatorsPath zipOutput.putNextEntry(ZipEntry(relativePath)) file.inputStream().use { input -> input.copyTo(zipOutput) } zipOutput.closeEntry() } } } versionFile.writeText(bundledWebBundleVersionName.get()) } } android { namespace = "com.gramiatechnologies.gramia" compileSdk = 34 defaultConfig { applicationId = resolvedApplicationId minSdk = 24 targetSdk = 35 versionCode = 18 versionName = resolvedVersionName resValue("string", "app_name", "\"${resolvedAppLabel}\"") buildConfigField("boolean", "IS_BETA_BUILD", isBetaBuild.toString()) buildConfigField("boolean", "USE_EMBEDDED_WEB_ASSETS", (useEmbeddedWebAssets || isBetaBuild).toString()) buildConfigField("boolean", "ENABLE_REMOTE_APP_UPDATES", (!isBetaBuild).toString()) buildConfigField("boolean", "ENABLE_REMOTE_WEB_BUNDLE_UPDATES", (!isBetaBuild).toString()) testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } } buildFeatures { buildConfig = true } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = "1.8" } sourceSets.getByName("main").assets.srcDir(bundledWebBundleAssetsDir.get().asFile) } tasks.matching { it.name.startsWith("merge") && it.name.endsWith("Assets") }.configureEach { dependsOn(generateBundledWebBundleAssets) } // Release lint reads every configured asset source while building its model. // Gradle 9 requires that relationship to be declared explicitly for generated assets. tasks.matching { it.name.contains("Lint", ignoreCase = true) }.configureEach { dependsOn(generateBundledWebBundleAssets) } dependencies { implementation("com.squareup.okhttp3:okhttp:4.12.0") // or latest version implementation("androidx.work:work-runtime-ktx:2.9.0") implementation("com.journeyapps:zxing-android-embedded:4.3.0") implementation("com.google.zxing:core:3.5.3") implementation("androidx.core:core-splashscreen:1.0.1") implementation("com.google.android.play:app-update:2.1.0") implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) implementation(libs.material) implementation(libs.androidx.activity) implementation(libs.androidx.constraintlayout) implementation(libs.firebase.messaging) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) }