Build types, flavors and variants

Runtime, build and Gradle Junior Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Predict the output

Two build types (debug, release) and two flavor dimensions: tier (free, paid) and env (staging, prod). How many variants?

Options
Hint 1 of 1

Multiply the counts.

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A 8

Correct. 2 × 2 × 2 = 8 variants, like freeStagingDebug.

Why not the others?
  • B 4. That ignores one dimension.
  • C 6. Variants multiply, they don't add.
  • D 2. That's only the build types.

30-second answer

Build types describe how you build, such as debug and release (signing, minification, debuggable). Product flavors describe what you build, such as free and paid, or staging and production, each with its own applicationId suffix, resources or code. Gradle combines them into variants, like freeRelease. Each variant can have its own source set, src/free/.

Practise saying it · 25 s. No recording, just a timer

Explain build variants.

Say your answer out loud, then check which of these points you covered:

  • Build type = how
  • Flavor = what
  • Variant = combination
  • Per-variant source sets

Deep dive

Flavors need a dimension; multiple dimensions multiply variants.

buildConfigField adds values to BuildConfig per variant (BuildConfig generation must be switched on).

Use androidComponents { beforeVariants { } } to disable variants you don't need.

Too many variants slow builds and CI.

Common mistakes

  • Putting environment switches in code with if-statements instead of flavors.
  • Creating variants nobody builds.
  • Secrets in buildConfigField.

Senior take & follow-ups

Define 'how' vs 'what', then the combination rule.

Follow-up questions

Think of your answer first, then open the hint.

  1. How many variants do 2 build types and 3 flavors give?

    Show hint

    Six.

  2. Where does flavor-specific code live?

    Show hint

    In src/<flavor>/java or kotlin.

Free tool

Keystore and APK fingerprint

Free tool: read the SHA-1 and SHA-256 fingerprints from a .jks, .p12, APK or certificate, for API key restrictions and signing setups.

Suggest a fix if something here is wrong or out of date.