Difference between BuildType, ProductFlavour and BuildVariant in Android

 BuildType 

  • It is used for build and packaging settings like signing configuration for a project. 
  • Eg. debug and release 
  • debug will used android debug certificate for packaging the APK file 
  • release build type will use user-defined release certificate for signing and packaging the apk 

buildTypes {
debug {
debuggable true
minifyEnabled false
buildConfigField("String", "TEST_TAGS", '"' + getTestTags() + '"')
buildConfigField("int", "TEST_USER_TYPE", getTestUserType())
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

ProductFlavors 

  • It is used to specify custom features, minimum and target API levels, device and API requirements like layout, drawable and custom code (prod code is slightly different than development code)
  • We can also create different white label apps with flavors 
  • Eg. we can use a base url with live server url in pro flavors while use a mock or testing server url in demo flavor for debugging purposes. 

android {
flavorDimensions "version"

productFlavors {
freeVersion {
//select the dimension of flavor
dimension "version"

//configure applicationId for app published to Play store
applicationId "com.niranjan.khatri.flavors.free"

//Configure this flavor specific app name published in Play Store
resValue "string", "flavored_app_name", "Free Khatri App"

}

paidVersion {
dimension "version"
applicationId "com.niranjan.khatri.flavors.paid"
resValue "string", "flavored_app_name", "Paid Khatri App"
}
}
}

BuildVariant 

The combination of BuildType and ProductFlavor is BuildVariant 

For Example: 

  • freeDebug 
  • freeRelease 
  • paidDebug 
  • paidRelease 

Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.

Read to know more in details: https://developer.android.com/studio/build/build-variants



Comments

Popular Posts