Build Types: debug & release
A build type describes how an app is built and packaged: debuggable or not, minified or not, which key signs it. AGP creates two for every app module:
debug |
release |
|
|---|---|---|
isDebuggable |
true |
false |
| Signed with | the auto-generated debug key ~/.android/debug.keystore |
nothing until you set a signingConfig |
isMinifyEnabled (R8) |
false |
false by default; you turn it on |
| Typical use | local development, instrumented tests | everything that leaves your machine |
You configure them in buildTypes {}, and you can add your own. A common third one is a staging build: release-like (no debugger, shrunk) but installable next to production, pointing at a test backend.
android {
buildTypes {
debug {
applicationIdSuffix = ".debug" // installs next to the release app
versionNameSuffix = "-debug"
}
release {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
create("staging") {
initWith(getByName("release")) // copy release's settings…
applicationIdSuffix = ".staging" // …then change what differs
signingConfig = signingConfigs.getByName("debug")
}
}
}Seeing the difference
The session builds all three and asks aapt2 what ended up in each APK's manifest. Watch the package names, the version names, the application-debuggable line and the file names:
mkdir -p hello/app/src/main/java/com/example/hello && cd hello
cat > settings.gradle.kts <<'KTS'
pluginManagement { repositories { google(); mavenCentral(); gradlePluginPortal() } }
dependencyResolutionManagement { repositories { google(); mavenCentral() } }
rootProject.name = "hello"
include(":app")
KTS
echo 'plugins { id("com.android.application") version "9.4.1" apply false }' > build.gradle.kts
cat > app/src/main/AndroidManifest.xml <<'XML'
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:label="Hello">
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
XML
cat > app/src/main/java/com/example/hello/MainActivity.java <<'JAVA'
package com.example.hello;
public class MainActivity extends android.app.Activity {
@Override protected void onCreate(android.os.Bundle state) {
super.onCreate(state);
android.widget.TextView view = new android.widget.TextView(this);
view.setText("Hello");
setContentView(view);
}
}
JAVA
cat > app/build.gradle.kts <<'KTS'
plugins { id("com.android.application") }
android {
namespace = "com.example.hello"
compileSdk = 36
defaultConfig {
applicationId = "com.example.hello"
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"
}
buildTypes {
debug {
applicationIdSuffix = ".debug"
versionNameSuffix = "-debug"
}
release {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"))
}
create("staging") {
initWith(getByName("release"))
applicationIdSuffix = ".staging"
signingConfig = signingConfigs.getByName("debug")
}
}
}
KTS
gradle wrapper > /dev/null
./gradlew assemble | grep -E '^> Task :app:(assemble|package|minify)|^BUILD'
find app/build/outputs/apk -name '*.apk' | sort
for apk in $(find app/build/outputs/apk -name '*.apk' | sort); do
echo "== $(basename $apk)"
aapt2 dump badging $apk | grep -oE "^package: name='[^']*' versionCode='[0-9]*' versionName='[^']*'|^application-debuggable"
done> Task :app:packageDebugResources
> Task :app:packageDebug
> Task :app:assembleDebug
> Task :app:packageReleaseResources
> Task :app:minifyReleaseWithR8
> Task :app:packageRelease
> Task :app:assembleRelease
> Task :app:packageStagingResources
> Task :app:minifyStagingWithR8
> Task :app:packageStaging
> Task :app:assembleStaging
> Task :app:assemble
BUILD SUCCESSFUL in 19s
app/build/outputs/apk/debug/app-debug.apk
app/build/outputs/apk/release/app-release-unsigned.apk
app/build/outputs/apk/staging/app-staging.apk
== app-debug.apk
package: name='com.example.hello.debug' versionCode='1' versionName='1.0-debug'
application-debuggable
== app-release-unsigned.apk
package: name='com.example.hello' versionCode='1' versionName='1.0'
== app-staging.apk
package: name='com.example.hello.staging' versionCode='1' versionName='1.0'
Three observations:
assemblebuilds every variant.assembleDebug,assembleReleaseandassembleStagingare the per-build-type tasks; on CI you almost always call one specific task instead ofassemble(orbuild, which also runs tests and checks for every variant).app-release-unsigned.apk. No signing config means no signature, and an unsigned APK can't be installed. The file name says so loudly. Signing Configs fixes that properly.- Staging got R8 and the debug key.
initWith(release)copiedisMinifyEnabled, so theminifyStagingWithR8task ran. Signing a test build with the debug key is fine; never do it for something that goes to a store.
Debuggable is the line that matters
application-debuggable only appears for the debug APK. A debuggable app lets anyone with USB access attach a debugger, read its private files with run-as and change its behaviour, so Google Play rejects debuggable uploads. If you ever see isDebuggable = true in a release block, treat it as a bug.
Build type properties you'll use
| Property | Purpose |
|---|---|
isDebuggable |
debugger access (see above) |
isMinifyEnabled, isShrinkResources |
R8 code shrinking and resource shrinking (R8) |
proguardFiles(...) |
keep rules for R8 |
signingConfig |
which key signs it (Signing) |
applicationIdSuffix, versionNameSuffix |
side-by-side installs, visible build labels |
buildConfigField, resValue, manifestPlaceholders |
per-type constants (next lessons) |
matchingFallbacks |
for custom build types: which library build type to use when a library has no staging |
initWith(...) |
copy another build type's settings |
matchingFallbacks matters as soon as you have library modules: if :core only has debug and release, an app's staging variant needs matchingFallbacks += listOf("release") to know which one to consume.
Test yourself
Why is the release APK named app-release-unsigned.apk in the session?
- R8 removed the signature
- The release build type has no signingConfig yet
- Release builds are never signed by AGP
- aapt2 strips signatures
What did initWith(getByName("release")) give the staging build type?
- Nothing; it only copies the name
- Release's settings, including isMinifyEnabled, which is why minifyStagingWithR8 ran
- The release signing key
- A separate applicationId
Which aapt2 dump badging line must never appear for an APK you upload to Google Play?
- launchable-activity
- application-debuggable
- uses-feature
- supports-screens