Build variants let you create different versions of your app easily. For example, one for testing (debug) and one for users (release).
0
0
Build variants (debug, release) in Android Kotlin
Introduction
When you want to test your app with extra tools before sharing it.
When you need a version of your app without debug info for app stores.
When you want to add special features only for testing.
When you want to keep your app secure by hiding keys in release builds.
When you want to speed up the app by removing debug code in release.
Syntax
Android Kotlin
android {
buildTypes {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-DEBUG"
debuggable true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}The debug build type is for testing and usually includes extra info.
The release build type is optimized and signed for publishing.
Examples
This example adds ".debug" to the app ID for debug builds and disables code shrinking in release.
Android Kotlin
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
}
release {
minifyEnabled false
}
}This example adds "-dev" to the version name in debug and sets signing for release.
Android Kotlin
buildTypes {
debug {
versionNameSuffix "-dev"
}
release {
signingConfig signingConfigs.release
}
}Sample App
This Gradle script defines two build variants: debug and release. Debug adds ".debug" to the app ID and "-DEBUG" to the version name, making it easy to identify. Release enables code shrinking and uses signing for publishing.
Android Kotlin
android {
compileSdk 33
defaultConfig {
applicationId "com.example.myapp"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-DEBUG"
debuggable true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}OutputSuccess
Important Notes
Always test your release build before publishing to catch issues.
Debug builds are slower but easier to fix problems in.
You can create more build variants for flavors like free or paid versions.
Summary
Build variants let you make different app versions from one project.
Debug is for testing; release is for publishing.
You control settings like app ID, version, and optimization per variant.