Build System
1. Gradle Basics
Q: What is Gradle and how does it work in Android?
Gradle is the build automation tool for Android. It:
- Compiles source code
- Manages dependencies
- Creates APK/AAB packages
- Runs tests
- Signs and optimizes releases
Android uses the Android Gradle Plugin (AGP) which adds Android-specific tasks.
Q: What are the key Gradle files?
| File | Purpose |
|---|---|
| settings.gradle.kts | Defines modules in project |
| build.gradle.kts (project) | Project-wide config, plugin versions |
| build.gradle.kts (module) | Module-specific config, dependencies |
| gradle.properties | Build settings, JVM config |
| local.properties | Local machine config (SDK path, secrets) |
Q: Groovy DSL vs Kotlin DSL?
| Groovy | Kotlin |
|---|---|
| Older, more examples | Type-safe, IDE support |
| Dynamic typing | Static typing, autocomplete |
.gradle extension |
.gradle.kts extension |
Kotlin DSL is now recommended for new projects.
2. Build Variants
Q: What are build types and product flavors?
Build types define how the app is built:
debug: Debuggable, no optimization, debug signingrelease: Optimized, minified, production signing
Product flavors define different versions:
free/paiddemo/fullstaging/production
Variants = Build Type × Product Flavors (e.g., freeDebug, paidRelease)
Q: What are common build type configurations?
| Property | Debug | Release |
|---|---|---|
isDebuggable |
true | false |
isMinifyEnabled |
false | true |
isShrinkResources |
false | true |
signingConfig |
debug | release |
applicationIdSuffix |
.debug | (none) |
Q: How do you configure different API endpoints per flavor?
Use buildConfigField:
productFlavors {
create("staging") {
buildConfigField("String", "API_URL", "\"https://staging.api.com\"")
}
create("production") {
buildConfigField("String", "API_URL", "\"https://api.com\"")
}
}
Access via BuildConfig.API_URL in code.
3. Dependencies
Q: Explain dependency configurations.
| Configuration | Meaning |
|---|---|
implementation |
Compile and runtime, not exposed to consumers |
api |
Compile and runtime, exposed to consumers |
compileOnly |
Compile only, not in runtime |
runtimeOnly |
Runtime only, not for compilation |
testImplementation |
For unit tests |
androidTestImplementation |
For instrumented tests |
Q: implementation vs api?
implementation: Dependency is internal, doesn't leak to consumersapi: Dependency is part of public API, consumers can use it
Prefer implementation—faster builds, better encapsulation.
Q: How do you handle dependency conflicts?
- Gradle uses highest version by default
- Use
constraintsto force specific version - Use
excludeto remove transitive dependencies - Check conflicts with
./gradlew dependencies - Use version catalogs for consistency
4. Version Catalogs
Q: What are version catalogs?
Centralized dependency management in libs.versions.toml:
[versions]
kotlin = "1.9.20"
compose = "1.5.4"
[libraries]
compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "compose" }
[bundles]
compose = ["compose-ui", "compose-material", "compose-foundation"]
[plugins]
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Usage: implementation(libs.compose.ui)
Benefits: Single source of truth, type-safe, IDE support.
5. ProGuard/R8
Q: What is R8 and what does it do?
R8 is Android's code shrinker (replaced ProGuard). It:
- Shrinks: Removes unused code
- Optimizes: Inlines methods, removes dead branches
- Obfuscates: Renames classes/methods to short names
- Reduces APK size: Significant size reduction
Q: What are ProGuard/R8 rules?
Rules tell R8 what to keep:
-keep class com.example.Model: Don't remove or rename-keepnames class ...: Don't rename (can still remove if unused)-keepclassmembers: Keep members, not class itself
Q: When are keep rules needed?
- Reflection (classes loaded by name)
- Serialization (Gson, JSON parsing)
- JNI (native methods)
- Custom views in XML
- Libraries without rules
Most libraries include their own rules via consumerProguardFiles.
6. Signing
Q: What is APK/AAB signing?
Digital signature that:
- Proves app comes from you
- Ensures APK hasn't been modified
- Required for Play Store and device installation
- Same key required for updates
Q: Debug vs Release signing?
| Debug | Release |
|---|---|
| Auto-generated debug keystore | Your production keystore |
| Same on all machines | Must be protected |
| Can't publish to Play Store | Required for Play Store |
Q: What is Play App Signing?
Google manages your app signing key:
- You upload with upload key
- Google re-signs with app signing key
- If upload key compromised, can reset it
- Key never leaves Google's servers
Recommended for all new apps.
7. Build Performance
Q: How do you speed up Gradle builds?
| Setting | Effect |
|---|---|
org.gradle.parallel=true |
Build modules in parallel |
org.gradle.caching=true |
Cache task outputs |
org.gradle.daemon=true |
Keep Gradle process running |
kapt.incremental.apt=true |
Incremental annotation processing |
| Increase JVM heap | org.gradle.jvmargs=-Xmx4g |
Q: What is incremental compilation?
Only recompile files that changed. Kotlin supports it, but annotation processors (KAPT) can break it. Consider KSP (Kotlin Symbol Processing) for better incremental support.
Q: How do you analyze build performance?
./gradlew --profile: Generate HTML report- Build Analyzer in Android Studio
--scanfor detailed Gradle build scan- Check configuration phase time (runs every build)
8. Modularization
Q: Why modularize an Android project?
- Faster builds: Only changed modules rebuild
- Better encapsulation: Clear boundaries,
internalvisibility - Parallel development: Teams work independently
- Reusability: Share modules across apps
- Dynamic delivery: Feature modules on demand
Q: What module types exist?
| Type | Purpose |
|---|---|
| app | Main application module |
| library | Shared code, produces AAR |
| feature | Self-contained feature |
| core | Common utilities, base classes |
| data | Repository, data sources |
| domain | Business logic, use cases |
Q: What's dynamic feature delivery?
Feature modules delivered on-demand or by condition:
- Install-time: Included in base APK
- On-demand: Downloaded when needed
- Conditional: Based on device features
Uses App Bundle format, Play Store handles delivery.
Quick Reference
| Topic | Key Points |
|---|---|
| Gradle Files | settings.gradle.kts (modules), build.gradle.kts (config), gradle.properties (settings) |
| Build Variants | Build types × Flavors; debug/release × free/paid |
| Dependencies | implementation (internal), api (exposed), version catalogs for consistency |
| R8 | Shrink, optimize, obfuscate; keep rules for reflection/serialization |
| Signing | Debug auto-generated; release keystore protected; Play App Signing recommended |
| Build Speed | Parallel, caching, daemon; avoid KAPT, use KSP; analyze with --profile |
| Modularization | Faster builds, encapsulation, parallel development; app/library/feature/core/data modules |