TExcelTAD
Home › Mobile Build Pipelines: Gradle/AGP, Xcode, SwiftPM & Fastlane › Field Notes: Flavors, SDK Levels & CI

Field Notes: Flavors, SDK Levels & CI

The second set of field notes is about the build matrix: how many variants you configure, which Android versions you support, and what CI actually needs to build.

Flavor explosion is real, and measurable

Every flavor dimension multiplies the variant count, and AGP creates tasks for every variant during configuration, whether you build it or not. The session measures it on the same tiny app with more and more flavors:

bash · try it yourself
mkdir -p hello/app/src/main && cd hello
cat > settings.gradle.kts <<'KTS'
pluginManagement { repositories { google(); mavenCentral(); gradlePluginPortal() } }
dependencyResolutionManagement { repositories { google(); mavenCentral() } }
rootProject.name = "hello"
include(":app")
KTS
echo 'plugins { id("com.android.application") version "9.4.1" apply false }' > build.gradle.kts
echo '<manifest xmlns:android="http://schemas.android.com/apk/res/android"><application android:label="Hello" /></manifest>' > app/src/main/AndroidManifest.xml
gradle wrapper > /dev/null
measure() {   # $1 = description, $2 = productFlavors block
  cat > app/build.gradle.kts <<KTS
plugins { id("com.android.application") }
android {
    namespace = "com.example.hello"
    compileSdk = 36
    defaultConfig { applicationId = "com.example.hello"; minSdk = 24; targetSdk = 36; versionCode = 1; versionName = "1.0" }
    $2
}
KTS
  ./gradlew -q tasks --all > tasks.txt
  variants=$(grep -E 'Assembles main output for variant [a-zA-Z]+
  

 tasks.txt | grep -vcE 'Test
  

)
  tasks=$(grep -c '^app:' tasks.txt)
  printf '%-34s %3s variants %5s tasks\n' "$1" "$variants" "$tasks"
}
measure "no flavors" ""
measure "tier (2)" 'flavorDimensions += "tier"; productFlavors { create("free") { dimension = "tier" }; create("paid") { dimension = "tier" } }'
measure "tier (2) x store (3)" 'flavorDimensions += listOf("tier", "store"); productFlavors { listOf("free", "paid").forEach { create(it) { dimension = "tier" } }; listOf("play", "galaxy", "huawei").forEach { create(it) { dimension = "store" } } }'
measure "tier (2) x store (3) x env (3)" 'flavorDimensions += listOf("tier", "store", "env"); productFlavors { listOf("free", "paid").forEach { create(it) { dimension = "tier" } }; listOf("play", "galaxy", "huawei").forEach { create(it) { dimension = "store" } }; listOf("dev", "qa", "prod").forEach { create(it) { dimension = "env" } } }'
no flavors                           2 variants   274 tasks
tier (2)                             4 variants   516 tasks
tier (2) x store (3)                12 variants  1470 tasks
tier (2) x store (3) x env (3)      36 variants  4308 tasks

Each line multiplies tasks and configuration time, IDE sync time and the CI matrix. Habits that keep it in check:

  • An environment is not a flavor. dev/qa/prod backends are usually a runtime setting or a build type (debug, staging, release), not a dimension that multiplies everything else.
  • Disable variants nobody ships with androidComponents { beforeVariants(selector()…) { it.enable = false } } (Product Flavors).
  • Prefer runtime configuration (remote config, server-side feature flags) for differences that don't need different binaries.
  • Store variants usually differ in a handful of values (billing library, store URL): a small flavor dimension, or a buildConfigField set by CI, not separate source trees.

minSdk vs targetSdk vs compileSdk

Setting Decides Policy
compileSdk which APIs you can call latest stable, always; it changes nothing at runtime
targetSdk which platform behaviour changes your app has opted into dictated by Google Play's yearly deadline
minSdk which devices can install the app a business decision based on your users

targetSdk is not optional. Google Play requires new apps and app updates to target an API level within about a year of the latest Android release; the deadline moves every August. When this course was written that meant API 35 (Android 15), moving to API 36 (Android 16) for the 2026 deadline; check Play Console's Target API level page for the current rule. Raising targetSdk turns on behaviour changes (permissions, background limits, edge-to-edge display, predictive back), so plan it as a project with testing, not a one-line change on deadline day.

minSdk is about users, not developers. Look at your own install base (Play Console → Statistics/Device catalog) before raising it, and remember that minSdk also unlocks build simplifications: minSdk 24 drops v1 signing (Verifying APKs), minSdk 21+ gets native multidex, higher levels let D8 skip desugaring work.

A runnable model of the three rules, as a CI check:

python · try it yourself
LATEST_STABLE_API = 36
PLAY_REQUIRED_TARGET = 35        # update yearly from Play's target API policy page

def check(module, compile_sdk, target_sdk, min_sdk):
    problems = []
    if compile_sdk < target_sdk:
        problems.append("compileSdk must be >= targetSdk")
    if target_sdk < PLAY_REQUIRED_TARGET:
        problems.append(f"targetSdk {target_sdk} < {PLAY_REQUIRED_TARGET}: Play will reject updates")
    if compile_sdk < LATEST_STABLE_API:
        problems.append(f"compileSdk {compile_sdk} is behind the latest stable API {LATEST_STABLE_API}")
    if min_sdk > target_sdk:
        problems.append("minSdk can't exceed targetSdk")
    return f"{module:<8} min {min_sdk:>2} target {target_sdk:>2} compile {compile_sdk:>2}: " + ("OK" if not problems else "; ".join(problems))

print(check(":app", 36, 36, 24))
print(check(":legacy", 34, 34, 21))
print(check(":widget", 35, 36, 26))
:app     min 24 target 36 compile 36: OK
:legacy  min 21 target 34 compile 34: targetSdk 34 < 35: Play will reject updates; compileSdk 34 is behind the latest stable API 36
:widget  min 26 target 36 compile 35: compileSdk must be >= targetSdk; compileSdk 35 is behind the latest stable API 36

What CI should build

Trigger Build
every push / pull request unit tests + assemble of one debug variant; lint if available
merge to main the release variants you ship, minified (R8 bugs only show up there), instrumented tests on a small device set
nightly every variant, the full device matrix, dependency update checks, size reports
tag the release job: signed bundle, verification, upload (GitHub Actions)

And always test a minified build before it reaches users: the debug build has no R8, so it can't show keep-rule bugs.

Test yourself

Three flavor dimensions with 2, 3 and 3 flavors and two build types produce how many variants?

  1. 8
  2. 10
  3. 18
  4. 36

Which setting does Google Play's yearly policy force you to raise?

  1. minSdk
  2. targetSdk
  3. versionName
  4. buildToolsVersion

Why should main-branch CI build a minified release variant, not only debug?

  1. Release builds are faster
  2. R8 problems (missing keep rules) only appear in minified builds
  3. Debug builds can't be tested
  4. Play requires it