import javax.inject.Inject plugins { id("com.android.application") } android { namespace = "nl.hansdezwart.bgclock" compileSdk = 36 defaultConfig { applicationId = "nl.hansdezwart.bgclock" minSdk = 26 targetSdk = 36 versionCode = 3 versionName = "1.2" } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } buildTypes { release { isMinifyEnabled = false } } } /** * The web app is not copied into the repo — it is read out of public_html at * build time, so the browser version and the app version cannot drift. * * sw.js is left behind on purpose: it is cache-first, and a service-worker cache * outlives an app upgrade, so it would go on serving the old index.html with no * way to clear it. Without the file the registration fails into its own .catch, * and the APK is the cache instead. */ abstract class SyncWebAssets : DefaultTask() { @get:InputDirectory @get:PathSensitive(PathSensitivity.RELATIVE) abstract val source: DirectoryProperty @get:OutputDirectory abstract val outputDir: DirectoryProperty @get:Inject abstract val fs: FileSystemOperations @TaskAction fun run() { fs.sync { from(source) { exclude("sw.js") } into(outputDir) } } } val webAssets = tasks.register("syncWebAssets") { source.fileValue(rootProject.file("../public_html")) } // the Variant API, not sourceSets.assets.srcDir: AGP 9 refuses a Provider there // because it can't tell generated from static, and this way the task dependency // is carried automatically androidComponents { onVariants { variant -> variant.sources.assets?.addGeneratedSourceDirectory(webAssets, SyncWebAssets::outputDir) } } dependencies { // the only dependency: WebViewAssetLoader, which serves the assets over a // real https origin so they count as a secure context implementation("androidx.webkit:webkit:1.16.0") }