Android多渠道打包(2)

    上一篇文章记录了使用美团walle实现多渠道打包的过程。这里再来记录一下友盟的多渠道打包。

    要实现友盟多渠道打包只需要申请appkey即可。

    并不需要sdk。当然,一般情况下,友盟统计 和 多渠道打包是一起使用的,所以可以引入:

compile 'com.umeng.analytics:analytics:latest.integration'

  
    1、 在清单文件中配置:
  

<application>

        ...

        <activity>

        </activity>

        ...


        <!--友盟---这里使用了动态配置,因为后面要配置多渠道-->
        <meta-data 
            android:value="${UMENG_APPKEY}" 
            android:name="UMENG_APPKEY"/>

        <meta-data 
            android:value="${UMENG_CHANNEL_VALUE}"
            android:name="UMENG_CHANNEL"/>


</application>

  
    2、在app的build.gradle中配置UMENG_APPKEY和 UMENG_CHANNEL_VALUE
  

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "27.0.2"
    defaultConfig {
        applicationId "com.ps.umengmaster"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        manifestPlaceholders = [UMENG_APPKEY: "59225e68310c9342160009d0"]//配置友盟appkey
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    //指定渠道
    /*productFlavors {
        baidu {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
        }
        wandoujia {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
        }
        //...
        //...
        //...
    }*/

    //批量处理
    productFlavors {
        default_channel{}
        wandoujia{}
        _360{}
        yingyongbao{}
        xiaomi{}
        baidu{}
        huawei{}
        jifeng{}
    }

    productFlavors.all { flavor ->
        flavor.manifestPlaceholders = [ UMENG_CHANNEL_VALUE:name ]
    }

    //指定打包的名称
    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                File outputDirectory = new File(outputFile.parent);
                def fileName
                if (variant.buildType.name == "release") {
//                    fileName = "app_v${defaultConfig.versionName}_${packageTime()}_${variant.productFlavors[0].name}.apk"
                    fileName = "seven_${variant.productFlavors[0].name}.apk"
                } else {
//                    fileName = "app_v${defaultConfig.versionName}_${packageTime()}_beta.apk"
                    fileName = "seven_${variant.productFlavors[0].name}_beta.apk"
                }
                output.outputFile = new File(outputDirectory, fileName)
            }
        }
    }


}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    /*umeng*/
    compile 'com.umeng.analytics:analytics:latest.integration'
}

  
    3、在项目根目录下,使用studio的Terminal执行打包命令:
  

gradlew assembleRelease

    打出来的是Release包,效果如下:

这里写图片描述

备注:当然了,使用gradlew assembleDebug可以打debug包。
  
————-分割线——————————————————————-
  

对于打包,我们除了可以使用命令行之外,可以在studio中:

Build -> Generate Signed APK…

这里写图片描述

  
    然后在弹出来的选择框中输入或选择对应的内容:
  

这里写图片描述
  
    然后Next(一路往下)即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值