python批量打多渠道包
安卓市场太多,一个一个手动打包太累而且容易出错。
也有用ant打包的,来看看python的批量打包方式:
举个例子,如友盟(真心不是给他打广告)的多渠道统计
我们只是需要动态的修改这个channel_value,然后打包就可以了。
思路
1.导出一个未签名的apk包,其中渠道号配置如上图。
2.使用apkTool解压apk包
3.根据渠道号修改channel_value
4.使用apktool重新打包为未签名的apk包
5.给未签名的apk包签名
这里选择使用python来实现这些功能,感谢金兄让我认识python(吐槽一下,python为什么没有大括号)
组织结构如下图:
其中channel为渠道号列表:
keystore文件夹内放置着测试工程的签名文件ApkTest.keystore
ApkTest.apk是未签名的apk包
下面就是最重要的MakeTool.py文件
- #!/usr/bin/python
- # coding=utf-8
- import os
- import shutil
- def readChannelfile(filename):
- f = file(filename)
- while True:
- line = f.readline().strip('\n')
- if len(line) == 0:
- break
- else:
- channelList.append(line);
- f.close()
- def backUpManifest():
- if os.path.exists('./AndroidManifest.xml'):
- os.remove('./AndroidManifest.xml')
- manifestPath = './temp/AndroidManifest.xml'
- shutil.copyfile(manifestPath, './AndroidManifest.xml')
- def modifyChannel(value):
- tempXML = ''
- f = file('./AndroidManifest.xml')
- for line in f:
- if line.find('channel_value') > 0:
- line = line.replace('channel_value', value)
- tempXML += line
- f.close()
- output = open('./temp/AndroidManifest.xml', 'w')
- output.write(tempXML)
- output.close()
- unsignApk = r'./bin/%s_%s_unsigned.apk'% (easyName, value)
- cmdPack = r'java -jar apktool.jar b temp %s'% (unsignApk)
- os.system(cmdPack)
- unsignedjar = r'./bin/%s_%s_unsigned.apk'% (easyName, value)
- signed_unalignedjar = r'./bin/%s_%s_signed_unaligned.apk'% (easyName, value)
- signed_alignedjar = r'./bin/%s_%s.apk'% (easyName, value)
- cmd_sign = r'jarsigner -verbose -keystore %s -storepass %s -signedjar %s %s %s'% (keystore, storepass, signed_unalignedjar, unsignedjar, alianame)
- cmd_align = r'zipalign -v 4 %s %s' % (signed_unalignedjar, signed_alignedjar)
- os.system(cmd_sign)
- os.remove(unsignedjar)
- os.system(cmd_align)
- os.remove(signed_unalignedjar)
- channelList = []
- apkName = 'ApkTest.apk'
- easyName = apkName.split('.apk')[0]
- keystore='./keystore/ApkTest.keystore'
- storepass='123456'
- alianame='ApkTest.keystore'
- output_apk_dir="./bin"
- if os.path.exists(output_apk_dir):
- shutil.rmtree(output_apk_dir)
- readChannelfile('./channel')
- print '-------------------- your channel values --------------------'
- print 'channel list: ', channelList
- cmdExtract = r'java -jar apktool.jar d -f -s %s temp'% (apkName)
- os.system(cmdExtract)
- backUpManifest()
- for channel in channelList:
- modifyChannel(channel)
- if os.path.exists('./temp'):
- shutil.rmtree('./temp')
- if os.path.exists('./AndroidManifest.xml'):
- os.remove('./AndroidManifest.xml')
- print '-------------------- Done --------------------'
执行也很简单 shell终端进入这个文件夹,执行python MakeTool.py就可以
执行后会在文件夹下生成bin文件夹,根据各个市场的签名文件夹就在里面
0资源分下载:http://download.csdn.net/detail/luck_apple/5108421
关于python可以参考:http://woodpecker.org.cn/abyteofpython_cn/chinese/