Build Android with Gradle (Build Type)

  • release (Default)
  • debug (Default)
  • custom build type (Ex: alpha, beta)
Build Type example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
android {
buildTypes {
debug {
applicationIdSuffix ".debug"
}

/* Creating new Build Types is as easy as using a new element under the buildTypes container,
* either to call initWith() or to configure it with a closure.
*/

beta.initWith(buildTypes.debug)
beta{
applicationIdSuffix ".beta"
versionNameSuffix ".beta"
}

alpha.initWith(buildTypes.debug)
alpha{
applicationIdSuffix ".alpha"
versionNameSuffix ".alpha"
}
}
}

Build Type Table

Property name Default values for debug Default values for release / other
debuggable true false
jniDebuggable false false
renderscriptDebuggable false false
renderscriptOptimLevel 3 3
applicationIdSuffix null null
versionNameSuffix null null
signingConfig android.signingConfigs.debug null
zipAlignEnabled false true
minifyEnabled false false
proguardFile N/A (set only) N/A (set only)
proguardFiles N/A (set only) N/A (set only)

每一個Build Type,都會產生相對應的 sourceSet 以及 task

  • sourceSet : src/<buildtypename>/
  • task : assemble<BuildTypeName>
android {
    sourceSets.alpha.setRoot('alpha')
    sourceSets.beta.setRoot('beta')
}

// task
// assembleAlpha
// assembleBeta