android 批量打渠道包

来源:互联网 发布:mac如何更改文件夹 编辑:程序博客网 时间:2024/05/16 19:29

之前写的脚本了,今天偶然发现,贴代码上来做个记录把。
应用场景是:

在应用分发的时候,要给不同渠道渠道包,简单说就是每个包里面有一个key是不同的。

应用市场的key可以是:

anzhi #安智市场360 #360助手xiaomi #小米应用超市mumayi #木蚂蚁wandoujia #豌豆荚baidu #百度市场huawei #华为市场lenovo #联想市场meizu #魅族sogou #搜狗手机助手PP #pp助手OPPO #oppo市场youyi #优亿市场gdt01 #应用宝gdt02 #广点通推广gdt03 #腾讯广点通03gdt04 #腾讯广点通04gdt05 #腾讯广点通05bd01 #wifi万能钥匙04bd02 #wifi万能钥匙05bd09 #百度09bd10 #百度10bd11 #百度11bd12 #百度12bd13 #百度13fst01 #粉丝通01fst02 #粉丝通02jrtt01 #今日头条01jrtt02 #今日头条02sogousem #搜狗搜索smsem #神马搜索360sem #360搜索wodou01 #沃豆渠道wodou02 #UC头条

简单做就是把包拆开,然后修改raw下的一个config文件,读取可以这样读:

private static String channel = null;private static String innerGetChannelFromFile() {    String temp = "";    String cfg;    try {        InputStream is = SeeYouApp.getContext().getResources().openRawResource(R.raw.channel_cfg);        InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8");        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);        while ((cfg = bufferedReader.readLine()) != null) {            temp += cfg;        }    } catch (Exception e) {        e.printStackTrace();    }    return temp;}

文件放在 res/raw/channel_cfg

按照常规的方式打包,打包完之后执行一下拆包,把channel_cfg中的key修改一下,修改的脚本是这样的:

#!/bin/sh#author Yeshen(me@yeshen.com)##no need to unzip zip-file , use 7z to update(delete + add) target file(eg:channel_cfg)#7z is need : sudo apt-get install p7zip-full#inputarchivesPath=app/build/outputs/channel/if [ ! -z "$1" ]; then    archivesPath=$1fi#settingzipper=7z$zipper --helpif [ $? -ne 0 ]; then        echo "sudo apt-get install p7zip-full"      exit ficonfig=channel_cfgLogName=Log.txtmarkets=markets.txtroot=$PWDoutput=app/build/outputstoolsPath=tools/targetPath=$output/apk/tempToolsPath=$output/archivesLogPath=$PWD/$output/$LogName#little cleanrm -rf $archivesPathrm -f $LogPathmkdir -p $archivesPathmarketsNameList=$(cat markets.txt | cut -d "#" -f1)apkList=$(ls -a $targetPath | grep .apk)for apkFile in $apkList;do     echo $apkFile    file=`echo $apkFile | sed s/.apk//`_    for channel in $marketsNameList;    do          newApkFile=$archivesPath$file$channel.apk        #little clean        rm -rf $tempToolsPath        mkdir -p $tempToolsPath                            #replace $config file        echo update $channel to $newApkFile        cp $targetPath/$apkFile $tempToolsPath/tmp.zip        cd $tempToolsPath        mkdir res        mkdir res/raw        echo $channel > res/raw/$config        echo "-----------$channel---------" >> $LogPath        $zipper d tmp.zip res/raw/$config 1>> $LogPath 2>&1        $zipper a tmp.zip res/raw/$config 1>> $LogPath 2>&1        cd $root        cp $tempToolsPath/tmp.zip $newApkFile        #jarsigner        #zipalign    donedoneecho "details message print app/build/outputs/Log.txt"rm -rf $tempToolsPathreturn

用这种方式,几分钟就弄完了。

当然在gradle中也可以配置,不过gradle中会全部重新编译,全部打包,一顿打包下来也要一两个小时,渠道包多的话。
当然也可以用美团的方案,不过有些渠道(例如360)会再加一层壳之类的,所以在某些渠道的分发上会有一点小麻烦。

原创粉丝点击