build: give libraries a real dev variant matching apps
- Commit
8ccc4498d8325087813d9777faaab94a067bb952- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-05 21:59 UTC (14 hours ago)
- Parents
9c70b42
Libraries previously published only debug/release, so app dev builds consumed the library debug variant through matchingFallbacks. The library convention now mirrors the app convention: a dev build type initialised from release (not debuggable, minify off, unit and instrumented coverage on), testBuildType=dev, and the AGP debug build type's variants disabled. App dev therefore matches library dev by exact build-type name; the remaining matchingFallbacks lists apply only to external AARs, which ship just debug/release. Library unit tests move from testDebugUnitTest to testDevUnitTest, so the single non-release library variant serves both assembleDev and tests, and the merged coverage report follows it. Release behaviour is unchanged. Docs in AGENTS.md, gradle.properties and library/ui's icon-codegen path updated to match. Verified: :library:assembleDev, :notes:assembleDev, :camera:assembleDev, :games:chess:assembleDev, :library:ui:lint and :library:ui:testDevUnitTest (1106 tests, 0 failures) all pass.
Diff
AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex 7bfd584c91..d4ed17e2bd 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -43,7 +43,7 @@ Monorepo: ~100 Gradle modules + Rust workspace. Do scoped work only. | locationprovider | `library/locationprovider/` | location abstraction | | aosp-stubs | `library/aosp-stubs/` | compile-only hidden-API stubs | | sdk:games/cast/openassistant | `sdk/games/`, `sdk/cast/`, `sdk/openassistant/` | achievements / casting / assistant tools |-| build-logic | `build-logic/` | `common-conventions-app`, `launcherIcon`, `rustNativeLib` |+| build-logic | `build-logic/` | `common-conventions-app`, `common-conventions-library`, `launcherIcon`, `rustNativeLib` | | lint-rules | `lint-rules/` | ToastUsage + DirectComposeAnimation + FileLength + DirectAndroidLog + DialogAsRoute + RouteScreenshotCoverage + FixtureDeterminism + NoDeadClick (fatal) + others | ### Apps (Gradle key → dir)@@ -92,6 +92,7 @@ The backend (relay server for findfamily/everysync/office/voxels) lives outside ``` Gradle defaults to a small daemon heap (`-Xmx8g`) with wide task parallelism (`org.gradle.workers.max=128` in `gradle.properties`; `./install all` escalates the heap, not the worker count). New build logic must be configuration-cache compatible. New/changed UI previews: `./gradlew :<module>:metadata`. Rust builds use the fast cargo profile for dev tasks and the release profile for release/ambiguous tasks, overridable with `-Pmodernapps.rustProfile=release|fast`.+Variants: apps and libraries both define only `dev` and `release` build types (the AGP `debug` type's variants are disabled in both convention plugins; neither `dev` variant is debuggable, and both initialise from `release`). App `dev` consumes library `dev` by exact build-type match — the `matchingFallbacks` lists in the conventions exist only for external AARs, which ship just debug/release. Library unit tests run as `:module:testDevUnitTest` (`testBuildType = "dev"` in both conventions), so one library variant serves assembleDev and tests. ## 4. Tools — use these, not raw gradle/adb Work in repo dir. Experiments/logs go in `analysis/` (gitignored).
build-logic/src/main/kotlin/TestCoverage.kt
diff --git a/build-logic/src/main/kotlin/TestCoverage.kt b/build-logic/src/main/kotlin/TestCoverage.ktindex e010e7c7f4..30d528eea3 100644--- a/build-logic/src/main/kotlin/TestCoverage.kt+++ b/build-logic/src/main/kotlin/TestCoverage.kt@@ -19,12 +19,14 @@ import org.gradle.api.specs.Spec const val MERGED_COVERAGE_TASK = "createMergedCoverageReport" /**- * Unit-test variant each convention's merged report is built from: apps test `dev`- * (`testDevUnitTest`, AGP `testBuildType = "dev"`), libraries test `debug`- * (`testDebugUnitTest`).+ * Unit-test variant each convention's merged report is built from: apps and+ * libraries both test `dev` (`testDevUnitTest`, AGP `testBuildType = "dev"`).+ * Libraries define a real `dev` build type mirroring the app one (see+ * common-conventions-library), so app `dev` builds consume library `dev`+ * variants by exact name match and library unit tests share those outputs. */ const val APP_UNIT_TEST_VARIANT = "dev"-const val LIBRARY_UNIT_TEST_VARIANT = "debug"+const val LIBRARY_UNIT_TEST_VARIANT = "dev" /** Stable output location of the merged report, relative to the module build directory. */ const val MERGED_COVERAGE_XML_PATH = "reports/coverage/merged/report.xml"
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 29ce0ada60..e4a31698b7 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -435,18 +435,21 @@ configure<com.android.build.api.dsl.ApplicationExtension> { initWith(getByName("release")) isMinifyEnabled = false isShrinkResources = false- // The Compose screenshot-test plugin (com.android.compose.screenshot) only- // registers its per-variant render tasks (preview/update/validateDevScreenshotTest)- // for a variant whose component is debuggable. `dev` is our testBuildType and is- // built from `release` (initWith), which is not debuggable, so without this the- // render tasks are never created and `metadata` fails with "No rendered previews- // found". `dev` is a developer build and never ships, so debuggable is correct here.- isDebuggable = true- // Libraries publish only debug/release variants. Prefer `debug`- // for `dev` consumers: library code is identical in both variants- // (libraries never minify), and `debug` is the variant library- // unit tests already build, so assembleDev reuses those outputs- // instead of compiling every library's release variant as well.+ // Dev variants are not debuggable (owner direction): a dev APK+ // installed on a device must not expose a debugger attach point.+ // initWith(release) already leaves this false; it is stated here+ // so the intent survives any change to the release type. The+ // Compose screenshot-test render tasks are host-side renders of+ // the testBuildType variant and do not need the installed APK to+ // be debuggable.+ isDebuggable = false+ // Project libraries publish a real `dev` variant (see+ // common-conventions-library), so `dev` consumers match it by+ // exact name — no fallback is exercised for any project library,+ // and assembleDev shares the one library variant that library+ // unit tests (testDevUnitTest) build. This fallback list only+ // ever applies to external (Maven) AARs, which ship just+ // debug/release. matchingFallbacks += listOf("debug", "release") ndk { abiFilters.clear()
build-logic/src/main/kotlin/common-conventions-library.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts b/build-logic/src/main/kotlin/common-conventions-library.gradle.ktsindex 9687520c27..f922ed7138 100644--- a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-library.gradle.kts@@ -57,6 +57,17 @@ wireRustHostLibsForUnitTests() wireRoomSchemaLocation() includeRobolectricClassesInCoverage() +extensions.configure<com.android.build.api.variant.LibraryAndroidComponentsExtension> {+ // Only `dev` and `release` exist, mirroring common-conventions-app. AGP+ // always creates a `debug` build type and forbids removing it, so disable+ // its variants instead — no debug variant means no assembleDebug /+ // compileDebugKotlin tasks are generated, and the single non-release+ // library variant (`dev`) is the one app dev builds and unit tests share.+ beforeVariants(selector().withBuildType("debug")) { variant ->+ variant.enable = false+ }+}+ configure<com.android.build.api.dsl.LibraryExtension> { // Same unit-test setup as common-conventions-app: merged manifest/resources for // Robolectric, plus the shared robolectric.properties (default sdk).@@ -84,6 +95,11 @@ configure<com.android.build.api.dsl.LibraryExtension> { minSdk = 31 } + // AGP auto-creates a `debug` build type; this repo only ships `dev` and+ // `release`. Point all test tasks at `dev` (its variants stay enabled+ // while `debug` variants are disabled above).+ testBuildType = "dev"+ buildTypes { named("release") { // Coverage for unit tests, mirroring common-conventions-app so@@ -91,12 +107,29 @@ configure<com.android.build.api.dsl.LibraryExtension> { // Enable coverage for unit tests enableUnitTestCoverage = true }- named("debug") {+ create("dev") {+ // initWith(release): dev variants are not debuggable (owner+ // direction), and `release` is the non-debuggable build type.+ // The library DSL has no `isDebuggable` accessor (that lives on+ // the application DSL), so initialising from release is also how+ // the variant's debuggable attribute stays false — matching app+ // `dev`, which sets isDebuggable = false explicitly.+ initWith(getByName("release"))+ // Libraries never minify, so dev/release code is identical apart+ // from coverage below; stating it keeps the variant honest if a+ // library ever opts into minification.+ isMinifyEnabled = false+ // Same coverage flags app `dev` sets (common-conventions-app).+ // `dev` is a developer build and never ships. // Enable coverage for unit tests enableUnitTestCoverage = true // Enable coverage for instrumentation tests (the :library:map // on-device renderer harness). enableAndroidTestCoverage = true+ // Project libraries all publish a `dev` variant, so consumers+ // match it by exact name; this fallback only ever applies to+ // external (Maven) AARs, which ship just debug/release.+ matchingFallbacks += listOf("debug", "release") } } @@ -174,8 +207,8 @@ dependencies { testImplementation(platform(libs.androidx.compose.bom)) testImplementation(libs.androidx.compose.ui.test.junit4) // Bare ComponentActivity for Robolectric Compose tests (createComposeRule needs the- // manifest entry; the artifact ships only a manifest, no code). Scoped to `debug`,- // the variant unit tests run against.+ // manifest entry; the artifact ships only a manifest, no code). It lands on the+ // unit-test classpath, whose variant is `dev` (testBuildType above). testImplementation(libs.androidx.compose.ui.test.manifest) // On-device test harness (src/androidTest; e.g. :library:map's renderer harness).@@ -191,8 +224,8 @@ dependencies { androidTestImplementation(libs.androidx.compose.ui.test.manifest) } -// Merged coverage: same shape as the app convention's task (see TestCoverage.kt), but for-// the `debug` variant libraries test (testDebugUnitTest). Writes XML+HTML to+// Merged coverage: same shape as the app convention's task (see TestCoverage.kt), for+// the `dev` variant libraries test (testDevUnitTest). Writes XML+HTML to // build/reports/coverage/merged/ with the shared generated-code excludes. Like the app // side, this deliberately avoids the Gradle `jacoco` plugin (AGP owns the Test-task // agent wiring) and reuses AGP's own `jacocoAnt` configuration for the report runtime,@@ -203,14 +236,14 @@ val jacocoAntClasspath: FileCollection = objects.fileCollection().from( tasks.register<JacocoReport>(MERGED_COVERAGE_TASK) { group = "verification"- description = "Merged JaCoCo report for the debug variant: unit-test .exec, " ++ description = "Merged JaCoCo report for the dev variant: unit-test .exec, " + "<task>Native companion .exec, plus androidTest .ec files (whichever " + "exist), with generated-code excludes."- dependsOn("testDebugUnitTest")+ dependsOn("testDevUnitTest") setJacocoClasspath(jacocoAntClasspath) classDirectories.from(mergedCoverageClassDirs(LIBRARY_UNIT_TEST_VARIANT)) executionData.from(- files(layout.buildDirectory.dir("outputs/unit_test_code_coverage/debugUnitTest"))+ files(layout.buildDirectory.dir("outputs/unit_test_code_coverage/devUnitTest")) .asFileTree.matching { include("*.exec") }, // The <task>Native companions (see RustNative.kt splitNativeLoadingTests) // are plain Gradle Test tasks, not AGP unit-test tasks, so their JaCoCo@@ -247,9 +280,9 @@ if (project.path in COMPILE_ONLY_STUB_MODULES) { // No real tests: the shared-test helper is injected into every library's // test source set, so Gradle 9 sees sources but discovers zero tests and // would fail the task. Allow empty discovery for stub modules only.- // Lazy: AGP creates testDebugUnitTest after this convention applies.+ // Lazy: AGP creates testDevUnitTest after this convention applies. tasks.withType<Test>().configureEach {- if (name == "testDebugUnitTest") {+ if (name == "testDevUnitTest") { failOnNoDiscoveredTests.set(false) } }
build-logic/src/main/kotlin/common-conventions-wear.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-wear.gradle.kts b/build-logic/src/main/kotlin/common-conventions-wear.gradle.ktsindex 4a3994582f..992507c37e 100644--- a/build-logic/src/main/kotlin/common-conventions-wear.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-wear.gradle.kts@@ -131,15 +131,12 @@ configure<com.android.build.api.dsl.ApplicationExtension> { initWith(getByName("release")) isMinifyEnabled = false isShrinkResources = false- // Debuggable parity with common-conventions-app's `dev`: the Compose- // screenshot-test plugin (com.android.compose.screenshot, applied by- // common-conventions-preview-metadata) only registers its render tasks- // for a debuggable variant. Wear's test build type stays `debug` (the- // AGP default, debuggable already), so today's screenshot tasks are the- // `*DebugScreenshotTest` ones; this keeps `dev` equally capable if the- // test build type ever moves to it, and `dev` never ships.- isDebuggable = true- matchingFallbacks += listOf("release")+ // Dev variants are not debuggable (owner direction), matching+ // common-conventions-app's `dev`.+ isDebuggable = false+ // Project libraries publish a real `dev` variant, matched by+ // exact name; `release` remains only as the external-AAR fallback.+ matchingFallbacks += listOf("dev", "release") } } }
gradle.properties
diff --git a/gradle.properties b/gradle.propertiesindex f7b51fd02d..a6cb38e024 100644--- a/gradle.properties+++ b/gradle.properties@@ -27,6 +27,10 @@ kotlin.code.style=official # Performance & Optimization org.gradle.configuration-cache=true+# Variants (see build-logic common-conventions-app/-library): apps and+# libraries define only dev+release build types (debug variants disabled,+# dev not debuggable, both initWith(release)); app dev matches library dev+# by exact name, and library unit tests are testDevUnitTest. android.enableR8.fullMode=true # One thread per R8 task (each runs in its own process, see settings.gradle.kts): # multi-threaded R8 output depends on thread timing, which broke F-Droid's
library/ui/AGENTS.md
diff --git a/library/ui/AGENTS.md b/library/ui/AGENTS.mdindex 579a52e425..f485efa276 100644--- a/library/ui/AGENTS.md+++ b/library/ui/AGENTS.md@@ -182,5 +182,5 @@ ``` ./gradlew :library:ui:compileDevKotlin ./gradlew :library:ui:lint-python3 scripts/check_icons_parity.py <old Icons.kt> library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt library/ui/build/generated/kotlin/generateDebugIcons/IconsGenerated.kt+python3 scripts/check_icons_parity.py <old Icons.kt> library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt library/ui/build/generated/kotlin/generateDevIcons/IconsGenerated.kt ```