Android编译变体BuildVariant详解

Android开发在构建apk时,AS会根据指定的编译变体选择指定的代码、资源和配置项进行apk构建,编译变体由两部分组成:

  • 编译类型–BuildType

  • 产品特性–ProductFlavor

编译变体由不同的ProductFlavor和BuildType组合而成


BuildVariant=ProductFlavor*BuildType

1. 编译类型–BuildType

在app module的build.gradle文件中,BuildType通过buildTypes{}块配置,默认情况下,AS自动生成了debug和releae两种buildType,还可以根据不同的需要修改或新增不同的buildType


android {

        defaultConfig {

            manifestPlaceholders = [hostName:"www.example.com"]

            ...

        }

        buildTypes {

            release {

                minifyEnabled true

                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            }



            debug {

                applicationIdSuffix ".debug"

                debuggable true

            }



            /**

             * The `initWith` property allows you to copy configurations from other build types,

             * then configure only the settings you want to change. This one copies the debug build

             * type, and then changes the manifest placeholder and application ID.

             */

            staging {

                initWith debug

                manifestPlaceholders = [hostName:"internal.example.com"]

                applicationIdSuffix ".debugStaging"

            }

        }

    }



上面的例子就定义了3中buildType,分别是debug、release和staging,各个buildType内可以配置applicationId前缀()、是否开启混淆(minifyEnabled)、是否开启mutildex(multiDexEnabled)、配置Proguard规则、设置不同的签名(signingConfig)等,具体可配置的选项如下

在这里插入图片描述

具体查看

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值