Gradle多渠道打包

今天以umeng为例讲解gradle的多渠道打包

1,在manifest里面配置如下信息

<meta-data android:name="UMENG_CHANNEL"
    android:value="${UMENG_CHANNEL_VALUE}"/>
2,在build.gradle里进行如下配置

def releaseTime() {
    return new Date().format("yyyy-MM-dd")
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.guojinbao.app"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 5
        versionName "1.5.0"
        // dex突破65535的限制
//        multiDexEnabled true
        // 默认是umeng的渠道
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "hwyy"]
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6  targetCompatibility JavaVersion.VERSION_1_6  }

    signingConfigs {

        release {
            storeFile file("../guojinbao_release.jks")
            storePassword "VmVTQi6n"
            keyAlias "guojinbao"
            keyPassword "VmVTQi6n"
        }
    }


    buildTypes {

        release {
            zipAlignEnabled true
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        // 输出apk名称为guojinbao_v1.0_2015-01-15_wandoujia.apk
                        def fileName = "guojinbao_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
                        output.outputFile = new File(outputFile.parent, fileName)
                    }
                }
            }
        }
    }

    // 友盟多渠道打包
    productFlavors {

        umeng {}
        sjzs_360 {}
        sjzs_bd {}
        sjzs_91 {}
        yyb {}
        xmsd {}
        hwyy {}
        pp_azzs {}
        oppo_sd {}
        wdj {}
        anzhi {}
        anzhuosc {}
        anzhuoyuan {}
        jfw {}
        lxlsd {}
        mmy {}
        yiyonghui {}
        yingyonghui {}
        yysc {}
        kuchuan {}
        sg_sjzs {}
        wy_yyzx {}
        ltwo {}
        azsc_3g {}
        sn_yysd {}
        ndw {}
        meizu {}
        azzj {}
        tykj {}
        mmsh {}
        lqsc {}
        xlyy {}
        anzhuosd {}
        alsc {}
        mgsc {}
        tongbutui {}
        vivo_sjzs {}
        tyyy {}
        kupai {}
        zx_yysd {}
    }

    productFlavors.all { flavor ->
        flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }
3,使用android studio右侧gradle功能


注意这里是app目录下

你可能感兴趣的:(android,apk,android,shell,gradle,Studio)