美文网首页
Gradle:第三篇(多渠道打包)

Gradle:第三篇(多渠道打包)

作者: 钉某人 | 来源:发表于2017-10-28 16:03 被阅读0次

    app所有开发测试结束之后就是往不同应用市场发布应用,这时我们要统计不同应用市场上app的使用情况,多渠道打包就成了重中之重。Gradle让多渠道打包变得相当顺手呢。

    1.创建渠道占位符

    在AndroidMainigest文件的Application节点下,创建meta-data的节点

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.dingmouren.test">
    
        <application
           ...
            >
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".DemoActivity"/>
    
            <!--多渠道打包:渠道占位符-->
            <meta-data
                android:name="PRODUCT"
                android:value="${CHANNEL_VALUE}"
                />
        </application>
    
    </manifest>
    
    2.配置gradle脚本并优化
    apply plugin: 'com.android.application'
    apply plugin: 'me.tatarka.retrolambda'
    android {
        compileSdkVersion 25
        buildToolsVersion "26.0.0"
        defaultConfig {
          ...
    
     }
        buildTypes {//构建类型
          ...
        }
        //多渠道打包
        productFlavors{
            product1{}
            product2{}
            product3{}
        }
        //这个领域会将productFlavors进行遍历,并将其name作为渠道名
        productFlavors.all{flavor -> flavor.manifestPlaceholders = [CHANNEL_VALUE:name]}
    
    dependencies {
        ...
    }
    
    

    相关文章

      网友评论

          本文标题:Gradle:第三篇(多渠道打包)

          本文链接:https://www.haomeiwen.com/subject/zudspxtx.html