美团Walle使用

相关链接

GitHub:https://github.com/Meituan-Dianping/walle
个人Demo存放于码云:https://gitee.com/personlin/walle

介绍

Walle(瓦力):Android Signature V2 Scheme签名下的新一代渠道包打包神器
瓦力通过在Apk中的APK Signature Block区块添加自定义的渠道信息来生成渠道包,从而提高了渠道包生成效率,可以作为单机工具来使用,也可以部署在HTTP服务器上来实时处理渠道包Apk的升级网络请求。
2种使用方式:
Gradle插件方式,方便快速集成
命令行方式,最大化满足各种自定义需求

安装

根目录 build.gradle

buildscript {
    dependencies {
        classpath 'com.meituan.android.walle:plugin:1.1.6'
    }
}

APP目录 build.gradle

apply plugin: 'walle'

dependencies {
    compile 'com.meituan.android.walle:library:1.1.6'
}

walle {
    // 指定渠道包的输出路径
    apkOutputFolder = new File("${project.buildDir}/outputs/channels")
    // 定制渠道包的APK的文件名称
    apkFileNameFormat = '${appName}-${packageName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk'
    // 渠道配置文件
//    channelFile = new File("D:/External/WalleApplication/channel")
//    print("${project.getProjectDir()}")   //D:\External\WalleApplication\app
//    channelFile = new File("${project.getProjectDir()}/channel")

    // 渠道&额外信息配置文件,与channelFile互斥  都存在时configFile优先执行
//    configFile = new File("D:/External/WalleApplication/config.json")
//    print("${project.getProjectDir()}")   //D:\External\WalleApplication\app
    configFile = new File("${project.getProjectDir()}/config.json")

}

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 名

打包

1)执行walle-cli命令

链接:https://github.com/Meituan-Dianping/walle/blob/master/walle-cli/README.md
查看渠道信息
java -jar walle-cli-all.jar show app\build\outputs\channels\app-com.lin.walle-360cn-release-v1.0-1-20180423-105856.apk
写入渠道 生成app-release_meituan.apk文件
java -jar walle-cli-all.jar put -c meituan app\build\outputs\apk\release\app-release.apk
写入渠道和额外信息
java -jar walle-cli-all.jar put -c meituan -e buildtime=20161212,hash=xxxxxxx app\build\outputs\apk\release\app-release.apk
指定输出文件
java -jar walle-cli-all.jar put -c meituan app\build\outputs\apk\release\app-release.apk app\build\outputs\apk\release\app-release111.apk

2)Gradle配置和命令

channelFile只支持渠道写入,如果想插入除渠道以外的其他信息,请在walle配置中使用configFile

1.配置

channelFile方式:

walle {
    // 指定渠道包的输出路径
    apkOutputFolder = new File("${project.buildDir}/outputs/channels");
    // 定制渠道包的APK的文件名称
    apkFileNameFormat = '${appName}-${packageName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk';
    // 渠道配置文件 channel放在APP下
    channelFile = new File("${project.getProjectDir()}/channel")
   print("${project.getProjectDir()}")   //D:\External\WalleApplication\app
   //channelFile = new File("D:/External/WalleApplication/channel")

}

configFile方式:都存在时configFile优先执行

walle {
    // 指定渠道包的输出路径
    apkOutputFolder = new File("${project.buildDir}/outputs/channels");
    // 定制渠道包的APK的文件名称
    apkFileNameFormat = '${appName}-${packageName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk';
    // 渠道配置文件
    configFile = new File("${project.getProjectDir()}/config.json")
}

2.打包

全部打包
gradlew clean assembleReleaseChannels
使用临时configFile config.json生成全部渠道包:
gradlew clean assembleReleaseChannels -PconfigFile=D:\External\WalleApplication\config.json
gradlew clean assembleReleaseChannels -PchannelFile=D:\External\WalleApplication\config.json
生成指定渠道 config.json和channel中的都可以
gradlew clean assembleReleaseChannels -PchannelList=meituan
支持 productFlavors
示例channel_product1
gradlew clean assemblechannel_product1ReleaseChannels

获取渠道信息

String channel = WalleChannelReader.getChannel(this.getApplicationContext());
ChannelInfo channelInfo= WalleChannelReader.getChannelInfo(this.getApplicationContext());
if (channelInfo != null) {
   String channel = channelInfo.getChannel();
   Map<String, String> extraInfo = channelInfo.getExtraInfo();
}
// 或者也可以直接根据key获取
String value = WalleChannelReader.get(context, "buildtime");

猜你喜欢

转载自blog.csdn.net/u010987039/article/details/80592721