Android Studio gradle 多渠道定制打包

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.sinyee.babybus.town"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 10
        versionName "1.0"
        multiDexEnabled true

        //setProperty("archivesBaseName", "$applicationId-$versionName@$versionCode")
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

    repositories {
        flatDir {
            dirs 'libs', '../modules/BBUnityPlayer/libs'
        }
    }

    productFlavors {
        productA001 {

        }

        productA002 {

        }

        productA003 {

        }

        productA003_sdk {

        }

        productA004 {

        }

        productA005 {
            targetSdkVersion 23
        }

        productA006 {

        }

        productA008 {

        }

        productA009 {

        }

        productA016 {

        }

        productA017 {

        }

        productA018 {

        }

        productA022 {

        }

        productA023 {
            targetSdkVersion 23
        }

        productA023_sdk {
            targetSdkVersion 23
        }
    }

    productFlavors.all { flavor ->
        String channel = name.substring("product".length())
        flavor.manifestPlaceholders = [CHANNEL_VALUE: channel, IS_HUAWEI_DRM: channel.equals("A023_sdk")]

        if(channel.equals("A023_sdk"))
            flavor.applicationIdSuffix ".huawei"

        if(applicationId.equals("com.sinyee.babybus.talk2kiki"))
            flavor.targetSdkVersion 23
    }

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            String channel = variant.flavorName.substring("product".length())
            String outputFileName = variant.applicationId + "-" + variant.versionName + "@" + variant.versionCode + "-" + channel + "-" + (variant.buildType.name) + ".apk"
            output.outputFile = new File(output.outputFile.parentFile, outputFileName);
        }

        variant.assemble.doLast {
            variant.outputs.each { output ->
                println "aligned " + output.outputFile
                println "unaligned " + output.packageApplication.outputFile

                File unaligned = output.packageApplication.outputFile;
                File aligned = output.outputFile
                if (!unaligned.getName().equalsIgnoreCase(aligned.getName())) {
                    println "deleting " + unaligned.getName()
                    unaligned.delete()
                }
            }
        }
    }

//    android.variantFilter { variant ->
//        variant.getFlavors().each { flavor ->
//            println variant.buildType.name + " " + flavor.name
//        }
//    }
}

dependencies {
    // compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':modules:BBUnityPlayer')
    productA023_sdkCompile project(':modules:Plugin_HuaweiDrm')

}
Android Studio gradle 多渠道定制打包_第1张图片
Paste_Image.png

你可能感兴趣的:(Android Studio gradle 多渠道定制打包)