Android 多渠道打包、多id、多名称打包

Android 多渠道打包、多id、多名称打包

签名设置

signingConfigs {
        debug {//开发
            storeFile file('D:/key_store/invest_andoird_keystore_debug.jks')
            keyAlias '*****'
            storePassword '*****'
            keyPassword '*****'
        }
        FXBTest {//测试
            storeFile file('D:/key_store/invest_andoird_keystore_debug.jks')
            keyAlias '*****'
            storePassword '*****'
            keyPassword '*****'
        }
        release {//生产
            storeFile file('D:/key_store/invest_andoird_keystore_debug.jks')
            keyAlias 'zhoujianxiong'
            storePassword 'tf2016'
            keyPassword 'tf2016'
        }
    }

buildTypes

buildTypes {
        debug {
            debuggable true         //是否允许debug
            minifyEnabled true     //不启用Proguard
            zipAlignEnabled false   //是否启用zipAlign压缩
            buildConfigField 'boolean', 'IS_DEBUG', 'true'              //是否输出日志
            buildConfigField 'boolean', 'IS_SHUT_DOWN_CONFIG', 'false'              //是否停机
            buildConfigField 'String', 'SERVER_URL', DEBUG_SERVER_URL   //对应服务器地址
            buildConfigField 'String', 'FILE_SERVER_URL', FILE_TEST_SERVER_URL    //对应文件服务器地址
            buildConfigField 'String', 'UMENG_APPKEY', TEST_UMENG_APPKEY            //友盟appkey
            buildConfigField 'String', 'UMENG_MESSAGE_SECRET', TEST_UMENG_MESSAGE_SECRET            //友盟UMENG_MESSAGE_SECRET
            buildConfigField 'String', 'WEI_XIN_SDK_KEY', TEST_WEI_XIN_SDK_APP_ID            //微信appkey
            buildConfigField 'String', 'WEI_XIN_SDK_SECRET', TEST_WEI_XIN_SDK_APP_SECRET            //微信_SECRET
            resValue "string", "app_name_fengxiangibao", "峰向标开发"    //APP名称
            manifestPlaceholders = [
                    "UMENG_APPKEY"        : TEST_UMENG_APPKEY,
                    "UMENG_MESSAGE_SECRET": TEST_UMENG_MESSAGE_SECRET
            ]
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
        //测试环境
        FXBTest {
            debuggable true        //是否允许debug
            minifyEnabled false      //不启用Proguard
            zipAlignEnabled true    //是否启用zipAlign压缩
            buildConfigField 'boolean', 'IS_DEBUG', 'true'              //是否输出日志
            buildConfigField 'boolean', 'IS_SHUT_DOWN_CONFIG', 'false'              //是否停机
            buildConfigField 'String', 'SERVER_URL', TEST_SERVER_URL    //对应服务器地址
            buildConfigField 'String', 'FILE_SERVER_URL', FILE_TEST_SERVER_URL    //对应文件服务器地址
            buildConfigField 'String', 'UMENG_APPKEY', TEST_UMENG_APPKEY            //友盟appkey
            buildConfigField 'String', 'UMENG_MESSAGE_SECRET', TEST_UMENG_MESSAGE_SECRET            //友盟UMENG_MESSAGE_SECRET
            buildConfigField 'String', 'WEI_XIN_SDK_KEY', TEST_WEI_XIN_SDK_APP_ID            //微信appkey
            buildConfigField 'String', 'WEI_XIN_SDK_SECRET', TEST_WEI_XIN_SDK_APP_SECRET            //微信_SECRET
            resValue "string", "app_name_fengxiangibao", "***"    //APP名称
            manifestPlaceholders = [
                    "UMENG_APPKEY"        : TEST_UMENG_APPKEY,
                    "UMENG_MESSAGE_SECRET": TEST_UMENG_MESSAGE_SECRET
            ]
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.FXBTest
        }
        release {
            debuggable false        //是否允许debug
            minifyEnabled true      //启用Proguard
            zipAlignEnabled true    //是否启用zipAlign压缩
            buildConfigField 'boolean', 'IS_DEBUG', 'false'             //是否输出日志
            buildConfigField 'boolean', 'IS_SHUT_DOWN_CONFIG', 'true'              //是否停机
            buildConfigField 'String', 'SERVER_URL', RELEASE_SERVER_URL //对应服务器地址
            buildConfigField 'String', 'FILE_SERVER_URL', FILE_SERVER_URL  //对应文件服务器地址
            buildConfigField 'String', 'UMENG_APPKEY', RELEASE_UMENG_APPKEY    //友盟appkey
            buildConfigField 'String', 'UMENG_MESSAGE_SECRET', RELEASE_UMENG_MESSAGE_SECRET    //友盟UMENG_MESSAGE_SECRET
            buildConfigField 'String', 'WEI_XIN_SDK_KEY', WEI_XIN_SDK_APP_ID            //微信appkey
            buildConfigField 'String', 'WEI_XIN_SDK_SECRET', WEI_XIN_SDK_APP_SECRET            //微信_SECRET
            resValue "string", "app_name_fengxiangibao", "***"        //APP名称
            manifestPlaceholders = [
                    "UMENG_APPKEY"        : RELEASE_UMENG_APPKEY,
                    "UMENG_MESSAGE_SECRET": RELEASE_UMENG_MESSAGE_SECRET
            ]
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }

多渠道打包

 flavorDimensions 'api'
    productFlavors {
        Fntest {
            // 测试版本号
            versionName VERSION_NAME_TEST
            // 测试包名(测试友盟推送时,需将包名改成正式 包名,否则会提示ResClass未初始化 )
            applicationId "c****ao.test"
        }
        FengXiangBiao {}
        fir {}
        xiaomi {}
        qh360 {}
        vivo {}
        oppo {}
        tencent {}
        anzhi {}
        sougou {}
        meizu {}
    }
    productFlavors.all {
        flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }

打包重命名

//将release版本的包名重命名,加上版本及日期
        android.applicationVariants.all { variant ->
            variant.outputs.all { output ->
                def flavorName = variant.productFlavors[0].name;
                def versionName = variant.productFlavors[0].versionName;
                if (versionName == null) {
                    versionName = android.defaultConfig.versionName;
                }
                def outputFile = output.outputFile
                if (outputFile != null && outputFile.name.endsWith('.apk')) {
                    def newName;
                    def buildType = variant.buildType.name;
                    if (buildType.equals('release')) {
                        newName = "FengXiangBiaoV${versionName}_${flavorName}.apk"
                    } else if (buildType.equals('debug')) {
                        newName = "FengXiangBiaoV${versionName}_debug_${releaseTime()}.apk"
                    } else {
                        newName = "FengXiangBiaoV${versionName}_test_${releaseTime()}.apk"
                    }
                    outputFileName = newName
                }
            }
        }

// 生成版本的时间
def releaseTime() {
    return new Date().format("yyyyMMddHH")
}

// APP的VersionCode
def generateVersionCode() {
    return new Date().format("yyyyMMddHH", TimeZone.getTimeZone("GMT+8"))
}


gradle.properties

VERSION_DEVELOP=0;
VERSION_PRO=1;
VERSIONCODE = 100
VERSIONNAME = 4.3.3
---
其他参数
---

你可能感兴趣的:(Android 多渠道打包、多id、多名称打包)