美文网首页
百度统计AS3.0多渠道打包

百度统计AS3.0多渠道打包

作者: 林祖朋 | 来源:发表于2018-05-07 14:25 被阅读18次

AndroidMinifest.xml必不可少的:

        <!-- 渠道商编号 -->
        <meta-data
            android:name="BaiduMobAd_CHANNEL"
            android:value="${BAIDU_CHANNEL_VALUE}" />

Module:app build.gradle里:

apply plugin: 'com.android.application'

android {
   
    defaultConfig {
        ···
        versionCode 100
       //版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号
       //这样维度就 是都是统一的了
        flavorDimensions "versionCode"
        versionName "1.0.0"
        ···
       //默认渠道是应用宝
        manifestPlaceholders = [BAIDU_CHANNEL_VALUE: "yingyongbao"]
    }
    signingConfigs {
        debug {
            storeFile file('app.jks')
            storePassword '123456'
            keyAlias 'xxx'
            keyPassword '123456'
        }
        release {
            storeFile file('app.jks')
            storePassword '123456'
            keyAlias 'xxx'
            keyPassword '123456'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
           //apk为release(即signingConfigs的release)时,指定渠道包
            signingConfig signingConfigs.release 
            applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                       //例如华为市场apk的名字为:app_name_v1.0.0(100)_huawei.apk
                        def fileName = "app_name_v${defaultConfig.versionName}(${defaultConfig.versionCode})_${variant.productFlavors[0].name}.apk"
                        //参数1表示生成apk的目录
                        outputFileName = new File("../../", fileName)
                    }
                }
            }
        }
    }
    productFlavors  {
       //应用宝市场
        yingyongbao {
            manifestPlaceholders = [BAIDU_CHANNEL_VALUE: "yingyongbao"]
        }
       //小米市场
        xiaomi {
            manifestPlaceholders = [BAIDU_CHANNEL_VALUE: "xiaomi"]
        }
        //华为市场
        huawei {
            manifestPlaceholders = [BAIDU_CHANNEL_VALUE: "huawei"]
        }
    }

}


dependencies {
  ···
  ···
}

相关文章

网友评论

      本文标题:百度统计AS3.0多渠道打包

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