Android多渠道打包

来源:互联网 发布:软件开发需求调研 编辑:程序博客网 时间:2024/06/14 05:36
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.+'}
0 0
原创粉丝点击