Android Signature V2 Scheme签名下的新一代渠道包打包神器
Walle(瓦力):Android Signature V2 Scheme签名下的新一代渠道包打包神器
瓦力通过在Apk中的
APK Signature Block区块添加自定义的渠道信息来生成渠道包,从而提高了渠道包生成效率,可以作为单机工具来使用,也可以部署在HTTP服务器上来实时处理渠道包Apk的升级网络请求。
为了方便大家的使用,我们提供了2种使用方式:
在位于项目的根目录
build.gradle文件中添加Walle Gradle插件的依赖, 如下:
buildscript { dependencies { classpath 'com.meituan.android.walle:plugin:1.1.7' } }
并在当前App的
build.gradle文件中apply这个插件,并添加上用于读取渠道号的AAR
apply plugin: 'walle'dependencies { compile 'com.meituan.android.walle:library:1.1.7' }
walle { // 指定渠道包的输出路径 apkOutputFolder = new File("${project.buildDir}/outputs/channels"); // 定制渠道包的APK的文件名称 apkFileNameFormat = '${appName}-${packageName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk'; // 渠道配置文件 channelFile = new File("${project.getProjectDir()}/channel") }
配置项具体解释:
new File("${project.buildDir}/outputs/apk")
apkFileNameFormat:定制渠道包的APK的文件名称, 默认值为
'${appName}-${buildType}-${channel}.apk'
projectName - 项目名字 appName - App模块名字 packageName - applicationId (App包名packageName) buildType - buildType (release/debug等) channel - channel名称 (对应渠道打包中的渠道名字) versionName - versionName (显示用的版本号) versionCode - versionCode (内部版本号) buildTime - buildTime (编译构建日期时间) fileSHA1 - fileSHA1 (最终APK文件的SHA1哈希值) flavorName - 编译构建 productFlavors 名
channelFile:包含渠道配置信息的文件路径。 具体内容格式详见:渠道配置文件示例,支持使用#号添加注释。
在需要渠道等信息时可以通过下面代码进行获取
String channel = WalleChannelReader.getChannel(this.getApplicationContext());
生成渠道包的方式是和
assemble${variantName}Channels指令结合,渠道包的生成目录默认存放在
build/outputs/apk/,也可以通过
walle闭包中的
apkOutputFolder参数来指定输出目录
用法示例:
./gradlew clean assembleReleaseChannels
./gradlew clean assembleMeituanReleaseChannels
channelFile只支持渠道写入,如果想插入除渠道以外的其他信息,请在walle配置中使用
configFile
walle { // 渠道&额外信息配置文件,与channelFile互斥 configFile = new File("${project.getProjectDir()}/config.json") }
configFile是包含渠道信息和额外信息的配置文件路径。
注意:
channelFile功能互斥,开发者在使用时选择其一即可,两者都存在时
configFile优先执行。
channel为key的情况
而对应的渠道信息获取方式如下:
ChannelInfo channelInfo= WalleChannelReader.getChannelInfo(this.getApplicationContext()); if (channelInfo != null) { String channel = channelInfo.getChannel(); Map extraInfo = channelInfo.getExtraInfo(); } // 或者也可以直接根据key获取 String value = WalleChannelReader.get(context, "buildtime");
我们推荐使用channelFile/configFile配置来生成渠道包,但有时也可能有临时生成渠道包需求,这时可以使用:
./gradlew clean assembleReleaseChannels -PchannelList=meituan
./gradlew clean assembleReleaseChannels -PchannelList=meituan,dianping
./gradlew clean assembleReleaseChannels -PchannelList=meituan -PextraInfo=buildtime:20161212,hash:xxxxxxx
注意: 这里的extraInfo以
key:value形式提供,多个以
,分隔。 - 使用临时channelFile生成渠道包:
./gradlew clean assembleReleaseChannels -PchannelFile=/Users/xx/Documents/channel- 使用临时configFile生成渠道包:
./gradlew clean assembleReleaseChannels -PconfigFile=/Users/xx/Documents/config.json
使用上述-P参数后,本次打包channelFile/configFile配置将会失效,其他配置仍然有效。
-PchannelList,
-PchannelFile,
-PconfigFile三者不可同时使用。
可以使用命令行工具来支持各类自定义的需求,具体使用方式详见:Walle CLI 使用说明
为了更好的满足大家的各类自定义需求,我们把对
APK Signing Block区块进行读写操作的模块进行了封装。
读写模块的使用说明详见:
对该工具的原理感兴趣的同学,可以移步美团Android新一代渠道包生成工具进行了解。
Copyright 2017 Meituan-DianpingLicensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.