Android 设置debug,release签名 多渠道打包配置

多渠道打包配置1: 

1. 多渠道打包Android:

  1.  在  AndroidManifest.xml 的application标签中添加:
   添加 <meta-data
                   android:name="UMENG_CHANNEL"
                   android:value="${UMENG_CHANNEL_VALUE}" />

2.  build.gradle的 android节点下配置:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.demo_42_startforegroundservice"
        minSdkVersion 23
        targetSdkVersion 27
        versionCode 1
        versionName "1.5.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        flavorDimensions "default"   // 配置多维度,这个必须要开启
    }
    buildTypes {
        release {
            minifyEnabled false
            // 配置release签名
            signingConfig signingConfigs.debug//不要忘了要在release的时候加入我么的签名配置信息
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            // 配置debug签名
            signingConfig signingConfigs.debug//不要忘了要在release的时候加入我么的签名配置信息
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    signingConfigs {
        debug {
//  默认路径在: 项目\app 路径下
            storeFile file('tophotoart.jks')
            storePassword "123456"
            keyAlias "dreamsdeng"
            keyPassword "123456"
        }
    }
    lintOptions {   // 这个可以配置一个,打包压缩优化,上传google play需要
        checkReleaseBuilds false
        abortOnError false
    }
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    //方式一:
//    productFlavors{
//        wandoujia{
//            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
//        }
//        xiaomi{
//            manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]
//        }
//
//        yingyongbao{
//            manifestPlaceholders=[UMENG_CHANNEL_VALUE: "yingyongbao"]
//        }
//
//    }


    //优化1:productFlavors申明,在all中替换
//    productFlavors{
//        wandoujia{
//            //manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
//        }
//        xiaomi{
//            //manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]
//        }
//    }
//    productFlavors.all { flavor ->
//        flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
//    }
    //优化2:在前面的基础上添加一个版本, 配置多渠道打包
    productFlavors{
        wandoujia{
            //manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
        }
        xiaomi{
            //manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]
        }
        qihu{

        }
        baidu{

        }
        huawei{

        }
        oppo{

        }
        vivo{

        }
    }
    productFlavors.all { flavor ->
        flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }
// 配置打包输出路径,输出名字
    applicationVariants.all { variant ->
        variant.outputs.all { 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)
                outputFileName = fileName
            }
        }
    }
 }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile(name:'xutils-3.5.1', ext:'aar')
}

3. 获取channle上次到服务器:

 String channel= getChannel();
        Toast.makeText(MainActivity.this,channel,Toast.LENGTH_SHORT).show();
  

当APP打开激活的时候,上传channel渠道路径到服务器,服务器做统计 

多渠道打包配置2:  

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27

    // //移除lint检测的error添加如下配置就ok了
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    defaultConfig {
        // 这里也可以直接改报名
        applicationId "mk.denganzhi.com.cehua"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
   // 必须配置
        flavorDimensions "versionCode"
    }

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

    // 多渠道打包配置, 配置新新包名,logo,appname,logo没有作用
    productFlavors {
        wandoujia {
            //manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
            applicationId "com.alpha.lock"
            buildConfigField('String', 'HTTP_HOST', '"https://app1.orangeiot.cn:8008"')
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "alpha",
                                    appname            : "alpha",
                                    app_icon           : "@drawable/logo",
                                    amapkey            : "18230744482cbb9f608cc3d1c1ef2e6d"]
        }
        alpha {
            applicationId "com.kaadas.lock"
            buildConfigField('String', 'HTTP_HOST', '"https://app1.orangeiot.cn:8008"')
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "kaadas",
                                    appname            : "kaadas",
                                    app_icon           : "@drawable/ic_launcher",
                                    amapkey            : "18230744482cbb9f608cc3d1c1ef2e64"]
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:27.1.1'
    compile 'com.android.support:design:27.1.1'
    compile 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值