Explain what a Gradle product flavor is and give a free vs pro example

Tests understanding of build-variant dimensions beyond build types. A strong answer defines flavorDimensions, sets free and pro applicationIdSuffix values, and explains variant generation. Red flag: conflating flavors with build types or manual APK renaming.
WHAT THIS TESTS: This question tests whether you understand the difference between product flavors and build types, and whether you can use Gradle's variant system to isolate code and resources for different product editions without duplicating modules. Interviewers want to see that you know flavors represent product dimensions while build types represent stages of the build pipeline, and that you can configure source sets and generated BuildConfig values in a maintainable way.
A GOOD ANSWER COVERS: First, define a flavor dimension such as tier inside the android block so Gradle knows how to group flavors. Second, declare free and pro productFlavors with distinct applicationIdSuffix values so both variants can install side by side, and add buildConfigField entries for feature flags like FEATURE_SET. Third, create source directories src/free/java and src/pro/java or res to hold edition-specific code and assets, letting the compiler merge them automatically. Fourth, explain that flavors cross product with build types like debug and release to generate the full variant matrix, for example freeDebug, freeRelease, proDebug, and proRelease. Fifth, mention that you can customize dependencies per flavor using freeImplementation or proImplementation to pull in analytics or billing libraries only where needed.
COMMON WRONG ANSWERS: A major red flag is treating build types as flavors by putting free and pro logic inside debug and release blocks. Another mistake is suggesting you maintain two separate app modules or use manual file copying to produce APKs, which destroys maintainability. Some candidates forget flavorDimensions entirely, which causes Gradle to emit an error in newer plugin versions. Others propose runtime if checks on a boolean everywhere instead of compile-time source-set isolation, which litters the codebase with conditionals and increases binary size.
LIKELY FOLLOW-UPS: The interviewer may ask how you handle a third dimension such as country or apiLevel, which requires adding another flavorDimension and understanding that Gradle multiplies all dimensions together. They might also ask how to resolve source-set merge conflicts when the same class exists in both src/free and src/main, or how variant-aware dependency resolution works with native libraries. You could also be asked how product flavors interact with the Android App Bundle and dynamic feature modules.
ONE CONCRETE EXAMPLE: Suppose you have a news reader app. In build.gradle you set flavorDimensions tier and add a free block with applicationIdSuffix .free and buildConfigField boolean FEATURE_ADS true, plus a pro block with applicationIdSuffix .pro and buildConfigField boolean FEATURE_ADS false. You place an AdsManager class in src/free/java/com/example/app that loads banners, and a no-op stub in src/pro/java/com/example/app with the same package and class name so the shared main code compiles against both. When you run assembleProRelease Gradle builds the pro variant with the stub and no ad SDK dependency, while assembleFreeDebug builds the free variant with real ads and a suffix that lets it install alongside the pro edition on the same device.
Source: developer.android.com
Read the original → developer.android.com
- #android
- #gradle
- #build-variants
- #product-flavors
- #intermediate
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.