安卓AndroidAndroid

Android项目实战:多渠道打包

2021-11-27  本文已影响0人  流失的语言

多渠道打包:

可以理解为:同时发布多个渠道的apk。分别上架不同的应用商店。这些apk带有各自渠道的标签,用于统计分析各个商店的下载次数等数据。

实现步骤

一、添加友盟渠道标签

添加位置:app目录下的 AndroidManifest.xml文件

添加语句:

<pre class="prism-token token  language-javascript" style="box-sizing: border-box; list-style: inherit; margin: 0.5em 0px; padding: 1em; color: rgb(204, 204, 204); background: rgb(80, 85, 107); border-radius: 3px; overflow: auto; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; overflow-wrap: normal; text-align: left; white-space: pre; word-spacing: 0px; word-break: normal; line-height: 1.5; tab-size: 4; hyphens: none; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">     <!--多渠道打包-->
        <meta-data android:value="${UMENG_CHANNEL_VALUE}" android:name="UMENG_CHANNEL"/></pre>

示例:

image.png

 二、添加渠道

添加几个,打包的时候就可以生成几个相应渠道的包

添加位置:app目录下的build.gradle文件 android{ ... } 内

添加代码:

<pre class="prism-token token  language-javascript" style="box-sizing: border-box; list-style: inherit; margin: 0.5em 0px; padding: 1em; color: rgb(204, 204, 204); background: rgb(80, 85, 107); border-radius: 3px; overflow: auto; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; overflow-wrap: normal; text-align: left; white-space: pre; word-spacing: 0px; word-break: normal; line-height: 1.5; tab-size: 4; hyphens: none; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">    productFlavors {
        xiaomi {}
        qihu360 {}
        baidu {}
        wandoujia {}
    }
    productFlavors.all {
        flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }</pre>

示例:

image.png

 三、签名信息配置

上面打出的包都是未签名的。上架需要签名包。

实现:

app目录下 android{ ... } 中添加 signingConfigs{ ... } 相关 。

image.png

    四、指定签名为release

添加位置:app目录下build.gradle文件 android{ ... } 内

添加代码:

<pre class="prism-token token  language-javascript" style="box-sizing: border-box; list-style: inherit; margin: 0.5em 0px; padding: 1em; color: rgb(204, 204, 204); background: rgb(80, 85, 107); border-radius: 3px; overflow: auto; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; overflow-wrap: normal; text-align: left; white-space: pre; word-spacing: 0px; word-break: normal; line-height: 1.5; tab-size: 4; hyphens: none; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">signingConfig signingConfigs.release</pre>
image.png

    五、gradle 实现多渠道打包

image.png

测试

可以看到outputs --> app 中多了各个渠道的release.apk 包

image.png

本文转自 https://cloud.tencent.com/developer/article/1130098,如有侵权,请联系删除。

相关视频

Android程序员中高级进阶学习/Java并发/多渠道打包原理

上一篇下一篇

猜你喜欢

热点阅读