简单的多渠道打包build.gradle模板

简单的多渠道打包build.gradle模板

之前看过一些多渠道打包的方法,现在自己总结了下,感觉可以提取一个build.gradle模板出来.
模板有一下功能:
1.根据versionCode(版本号)来修改app名
2.通过manifestPlaceholders来修改AndroidMainfest中预先定义好的渠道号

build.gradle模板:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.duoqudao"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    signingConfigs {
        release {//这里配置你的keyStore
            storeFile file("yourJks.jks")
            storePassword "passWord"
            keyAlias "yourKeyAlias"
            keyPassword "passWord"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //根据versionCode的修改apk名
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    output.outputFile = new File(output.outputFile.parent,
                            output.outputFile.name.replace(".apk", "-" + versionCode + ".apk")
                    )
                }
            }
        }
        debug {
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    output.outputFile = new File(output.outputFile.parent,
                            output.outputFile.name.replace("app-debug", "yourAppName" + versionCode)
                    )
                }
            }
            debuggable true
        }
    }
    //只需要将你想要打包的应用市场写在下面就可以了
    productFlavors {
        huawei {}
        xiaomi {}
        oppo {}
        meizu {}
        leshi {}
//这里很关键,下面代码会将打包的那个apk的名字通过占位符${CHANNEL_VALUE}赋给AndroidMainfest中
        //<meta-data android:name="TD_CHANNEL_ID"
        //android:value="${CHANNEL_VALUE}" />
//之后在代码中你可以通过这个CHANNEL_VALUE做很多事情,比如启动页展示应用市场的logo就需要通过CHANNEL_VALUE来判断
        productFlavors.all { flavor ->
            flavor.manifestPlaceholders = [CHANNEL_VALUE: name]
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值