Using Gradle in Android: Build Variants, Build Types, and Manifest Placeholders
Article Summary
Enes İğneci from Teknasyon Engineering breaks down the Gradle configuration secrets that separate amateur Android builds from production-ready apps. If you've ever shipped the wrong API key to production, this one's for you.
Managing multiple environments (dev, staging, production) in Android requires mastering three Gradle features most developers underutilize. This practical guide walks through build variants, build types, and manifest placeholders with real code examples using Kotlin DSL.
Key Takeaways
- Build variants let you run staging and production apps side-by-side with different bundle IDs
- Manifest placeholders inject environment-specific API keys dynamically at build time
- resValue() generates gradle-managed string resources for base URLs per environment
- Product flavors plus build types create automatic variant combinations (stageDebug, prodRelease, etc.)
Proper Gradle configuration eliminates hardcoded credentials and enables safe multi-environment testing on a single device.
About This Article
Android developers often struggle to keep testing, staging, and production environments separate. It's easy to accidentally ship the wrong credentials or API keys to the wrong deployment target.
Enes İğneci uses Gradle's flavorDimensions and productFlavors to create stage and prod variants. Each variant has its own applicationIdSuffix and manifestPlaceholders that inject the right ANALYTICS_API_KEY at build time.
Developers can build and install multiple app variants on one device at the same time. The com.enesigneci.playground.stage and com.enesigneci.playground bundle IDs each get their own auto-generated gradleResValues.xml file with the correct BASE_URL for that environment.