Android多渠道打包


apply plugin: 'com.android.application'

repositories {
    jcenter()
}

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.1"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        // 修改dex 65536的限制
        multiDexEnabled true
        // AndroidManifest.xml文件中UMENG_CHANNEL的value为${UMENG_CHANNEL_VALUE}
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "channel_name"]
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    // 签名文件
    signingConfigs {
        debug {
            // debug签名
            storeFile file("/path/xx-debug.jks")
            storePassword "密码"
            keyAlias "别名"
            keyPassword "签名密钥的密码"
        }
        release {
            // relase签名
            storeFile file("/path/xx-release.jks")
            storePassword "密码"
            keyAlias "别名"
            keyPassword "签名密钥的密码"
        }
    }

    // 构建类型
    buildTypes {
        debug {
            // debug模式下,显示log
            buildConfigField("boolean", "LOG_DEBUG", "true")
           // 版本名前缀
            versionNameSuffix "-debug"
            // 不开启混淆
            minifyEnabled false
            // 不开启ZipAlign优化
            zipAlignEnabled false
            // 不移除无用的resource文件
            shrinkResources false
            // 使用debug签名
            signingConfig signingConfigs.debug

        }
        release {
            // release模式下,不显示log
            buildConfigField("boolean", "LOG_DEBUG", "false")
            // 版本名前缀
            versionNameSuffix "-relase"
            // 开启混淆
            minifyEnabled true
            // 开启ZipAlign优化
            zipAlignEnabled true
            // 移除无用的resource文件
            shrinkResources true
            // 使用release签名
            signingConfig signingConfigs.release
            // 混淆文件位置
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    // 渠道Flavors,配置不同的渠道
    productFlavors {
        GooglePaly {}
        xiaomi {}
        umeng {}
        _360 {}
        wandoujia {}
        yingyongbao {}
        whatever {}
    }

    // 批量配置渠道
    productFlavors.all {
        flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }

    applicationVariants.all {
        variant ->
            variant.outputs.each {
                output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
                        output.outputFile = new File(outputFile.parent, fileName)
                    }
            }
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值