build: generate per-app Theme.General splash icon override
- Commit
209695e0c4624f2d326bb9332b6b10a569bad74f- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-05 22:54 UTC (13 hours ago)
- Parents
e17db41
GenerateLauncherIconTask (common-conventions-app only, new optional
splashTheme input) now also emits values/generated_splash_theme.xml:
Theme.General parent=Theme.General.Base
android:windowSplashScreenAnimatedIcon=@mipmap/ic_launcher
A shared library theme cannot reference @mipmap/ic_launcher - AAPT's
library link fails with 'resource mipmap/ic_launcher not found'
(verified on :library before this change) - because the icon only
exists in the final app, where build-logic generates it from that
app's launcherIcon symbol. Generating the one-item override in the app
module is the cleanest resolution: no per-app committed files, no
manifest changes, and one values file suffices because Base resolves
per configuration (night/v33) through the parent chain. Wear modules
leave splashTheme unset: they do not depend on :library, so the parent
would not resolve (watch-wear keeps its own Theme.WatchWear).
Per-app icons therefore resolve from each app's existing
launcherIcon symbol: notes=subject, camera=photo_camera,
weather=partly_cloudy_day, web=language, and so on for every app.
Verified in merged APKs with aapt2 dump resources: every app shows
style/Theme.General parent=style/Theme.General.Base with
0x0101062d (windowSplashScreenAnimatedIcon)=@mipmap/ic_launcher over
Base's 0x0101062c (windowSplashScreenBackground)=?colorBackground,
0x0101062e (animation duration)=0 and 0x01010630 (icon background)=
transparent, with no windowDisablePreview item. Weather additionally
shows Theme.Weather pinning splash+window background to its own
@color/window_background. :notes/:camera/:weather/:web
assembleRelease + lint/lintVitalRelease pass.Diff
build-logic/src/main/kotlin/LauncherIconGen.kt
diff --git a/build-logic/src/main/kotlin/LauncherIconGen.kt b/build-logic/src/main/kotlin/LauncherIconGen.ktindex a21f4043ea..bd4cc1c56e 100644--- a/build-logic/src/main/kotlin/LauncherIconGen.kt+++ b/build-logic/src/main/kotlin/LauncherIconGen.kt@@ -4,6 +4,7 @@ import org.gradle.api.file.DirectoryProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.Input import org.gradle.api.tasks.Internal+import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import java.net.URI@@ -42,6 +43,16 @@ abstract class GenerateLauncherIconTask : DefaultTask() { @get:Input abstract val scale: Property<Double> + /**+ * True only for app modules (set by `common-conventions-app`): also emit the+ * per-app `Theme.General` splash override (see [SPLASH_THEME]). Wear modules+ * leave this unset โ they do not depend on `:library`, so the parent style+ * would not resolve there.+ */+ @get:Input+ @get:Optional+ abstract val splashTheme: Property<Boolean>+ @get:Internal abstract val cacheDir: DirectoryProperty @@ -69,6 +80,17 @@ abstract class GenerateLauncherIconTask : DefaultTask() { val mipmapDir = outputDir.get().asFile.resolve("mipmap-anydpi-v26").apply { mkdirs() } mipmapDir.resolve("ic_launcher.xml").writeText(ADAPTIVE_ICON) mipmapDir.resolve("ic_launcher_round.xml").writeText(ADAPTIVE_ICON)++ // Per-app splash theme: :library's Theme.General.Base cannot name+ // @mipmap/ic_launcher (a library link has no app icon), so the app+ // module โ where the generated icon above does resolve โ defines+ // Theme.General itself as Base plus its own splash icon. One values+ // file is enough: Base resolves per configuration (night/v33) through+ // the parent chain.+ if (splashTheme.orNull == true) {+ val valuesDir = outputDir.get().asFile.resolve("values").apply { mkdirs() }+ valuesDir.resolve("generated_splash_theme.xml").writeText(SPLASH_THEME)+ } } private fun fetchRawSymbol(sym: String, gitRef: String): String {@@ -135,5 +157,16 @@ abstract class GenerateLauncherIconTask : DefaultTask() { |</adaptive-icon> | """.trimMargin()+ val SPLASH_THEME = """+ |<?xml version="1.0" encoding="utf-8"?>+ |<!-- Generated per app: this app's launcher icon as the Android 12+ splash+ | icon, over the shared splash background from Theme.General.Base. -->+ |<resources>+ | <style name="Theme.General" parent="Theme.General.Base">+ | <item name="android:windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>+ | </style>+ |</resources>+ |+ """.trimMargin() } }
build-logic/src/main/kotlin/common-conventions-app.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts b/build-logic/src/main/kotlin/common-conventions-app.gradle.ktsindex e4a31698b7..e1a8cdbd3f 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -217,6 +217,9 @@ extensions.configure<com.android.build.api.variant.ApplicationAndroidComponentsE ) { symbol.set(launcherIcon.symbol) scale.set(launcherIcon.scale)+ // Apps also get the generated Theme.General splash override (their own+ // icon over :library's Theme.General.Base); wear modules must not.+ splashTheme.set(true) ref.set(materialSymbolsRef) cacheDir.set(materialSymbolsCache) }