Difference between Build Type, Flavour, and Build Variant in Android

查看原文请点击:
Difference between Build Type, Flavour, and Build Variant in Android

Build Type
Build Type refers to build and packaging settings like signing configuration for a project. For example,debug and release build types. The debug will use android debug certificate for packaging the APK file. While, release build type will use user-defined release certificate for signing and packaging the APK.

Build types are defined in app’s build.gradle file like this:

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            debuggable true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

Flavour

A flavor is used to specify custom features, minimum and target API levels, device and API requirements like layout, drawable and custom code (for example, if production code is slightly different than development code). This can help create different white label apps as well. Flavours can vary in adding different features or customizing exisitng features, different icons and resources, different styles and strings etc. A simple example of flavour can be to use the live server url as base url for Retrofit in one flavour while adding mock or testing server url for debugging purposes.

Flavours are defined in app’s build.gradle file like this:

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

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

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

        }

        paidVersion {
            dimension "version"
            applicationId "com.pcc.flavors.paid"
            resValue "string", "flavored_app_name", "Paid Great App"
        }
    }
}

Build Variant

The combination of Build Type and Flavor is known as Build Variant. For example, for above build types (debug and release) and product flavours (free and paid versions), build variants can be freeDebug, freeRelease, paidDebug, paidRelease.

You can view build variants in Android Studio at View -> Tool Windows -> Build Variants.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,486评论 0 10
  • 欢迎大家关注我的公众号,各位的关注将是我持续输出优质内容的最大动力!谢谢! 自我介绍下,作为一名热爱无人机...
    余莫愁阅读 249评论 0 0
  • 加到几点看得开
    鲁晓明BrightLu阅读 166评论 0 0
  • 看到你 小小的你 那一瞬间 我的目光就无法移开 你的巴掌小脸 你的纤巧鼻梁 你的淡淡自信 在一个最最普通的初春清晨...
    吴芸茜阅读 359评论 0 1