android 自动化编译,批量打包
2015-04-30 16:18
459 查看
android 自动化编译,批量打包
ant 配置
android update 命令
使用 AntDemo 的 文件
文件编码问题
python 脚本
1.ant 配置
/article/4959316.html 。电脑已经安装过cocos, ant 已经配置好了。
2.(我的android项目引用了 user library) 打开终端,
cd 到android 主工程,执行命令
–path :表示路径
–name :表示项目名称 可以随便命名
–target :SDK 版本,具体数字可以 执行 android list targets 命令查看
–subprojects : 表示附带Lib 工程
再 cd 到库工程 , 执行命令
参数解释同上
到 https://github.com/sinkcup/AntDemo 下载工程文件。 下载custom_rules.xml,放到项目目录中,然后执行:
ant auto-debug -Dversion=time
即可自动打包,生成的包在./bin/中。
具体操作可以查看 https://github.com/sinkcup/AntDemo 的说明。
保证所有的 源文件的编码格式 是 utf-8
如果需要批量编译 N 多个渠道包,每个渠道包的包名和渠道号都不同。具体需求是配置一个csv文件,每一行表示一个APK包,每行数据包括,游戏名,包名,渠道号等等, 然后根据每一行数据生产一个APK包。
使用python 来实现这些业务逻辑。
5.1 读取csv
5.2 修改游戏名等
新建一个模板文件 strings.xml
然后使用python 替换掉相应的字符(如APPName 游戏名),再覆盖到工程中相应的文件。
#修改游戏的名字
附上完整的 python 脚本
ant 配置
android update 命令
使用 AntDemo 的 文件
文件编码问题
python 脚本
1.ant 配置
/article/4959316.html 。电脑已经安装过cocos, ant 已经配置好了。
2.(我的android项目引用了 user library) 打开终端,
cd 到android 主工程,执行命令
android update project --path . --name MainProject --target 4 --subprojects
–path :表示路径
–name :表示项目名称 可以随便命名
–target :SDK 版本,具体数字可以 执行 android list targets 命令查看
–subprojects : 表示附带Lib 工程
再 cd 到库工程 , 执行命令
android update project --path . --name LibProject --target 4
参数解释同上
到 https://github.com/sinkcup/AntDemo 下载工程文件。 下载custom_rules.xml,放到项目目录中,然后执行:
ant auto-debug -Dversion=time
即可自动打包,生成的包在./bin/中。
具体操作可以查看 https://github.com/sinkcup/AntDemo 的说明。
保证所有的 源文件的编码格式 是 utf-8
如果需要批量编译 N 多个渠道包,每个渠道包的包名和渠道号都不同。具体需求是配置一个csv文件,每一行表示一个APK包,每行数据包括,游戏名,包名,渠道号等等, 然后根据每一行数据生产一个APK包。
使用python 来实现这些业务逻辑。
5.1 读取csv
def startBuild(): clear() with open('config.csv') as csvfile: reader = csv.DictReader(csvfile) for row in reader: #print row['Name'], row['Package'],row['APPID'],row['APPKey'],row['Channel'] doBuildAPK(row) csvfile.close()
5.2 修改游戏名等
新建一个模板文件 strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">APPName</string> <string name="company">COMPANY</string> <string name="tel">TEL</string> </resources>
然后使用python 替换掉相应的字符(如APPName 游戏名),再覆盖到工程中相应的文件。
#修改游戏的名字
def changeName(name,company,tel): input = open('./buildConfig/strings.xml', 'r') inputStr=input.read().replace('APPName',name) inputStr=inputStr.replace('COMPANY',company); inputStr=inputStr.replace('TEL',tel); wf = open('./res/values/strings.xml', 'w') wf.write(inputStr) wf.close() input.close
附上完整的 python 脚本
#!/usr/bin/env python
# coding: utf-8
import csv
import sys
import os, os.path
#修改游戏的名字
def changeName(name,company,tel): input = open('./buildConfig/strings.xml', 'r') inputStr=input.read().replace('APPName',name) inputStr=inputStr.replace('COMPANY',company); inputStr=inputStr.replace('TEL',tel); wf = open('./res/values/strings.xml', 'w') wf.write(inputStr) wf.close() input.close
#修改计费代码
def changePayCodeFile(AppID,AppKey):
input = open('./buildConfig/paycode.properties', 'r')
fileStr=input.read().replace('ID',AppID)
fileStr=fileStr.replace('KEY',AppKey)
# print fileStr
index=1
while index <= 15 :
rCode='CODE'+ str( index )
newCode=AppID+'%02d'%index
fileStr=fileStr.replace(rCode,newCode)
index=index+1
wf = open('./assets/paycode.properties', 'w')
wf.write(fileStr)
wf.close()
input.close
def changePackageName(package):
input = open('./buildConfig/AndroidManifest.xml', 'r')
inputStr=input.read().replace('00000PACAKAGENAME00000000',package)
wf = open('./AndroidManifest.xml', 'w')
wf.write(inputStr)
wf.close()
input.close
#修改关于信息
def changeInfo(Company,Tel):
pass
def changeProject(info):
# changePackageName( info['Package'] )
changeName(info['Name'], info['Company'] ,info['Tel'])
changePayCodeFile( info['APPID'] , info['APPKey'] )
def doBuildAPK(info):
cmd='rm ./bin.*apk'
os.system(cmd)
changeProject(info)
cmd='ant auto-release -DUMENG_CHANNEL=%s -Dpackage=%s -Dversion=time'%( info['Channel'] ,info['Package'])
os.system(cmd)
cmd='mv ./bin/*.apk ./target/%s_%s_%s.apk'%(info['Name'],info['Company'],info['Package'])
os.system(cmd)
##清空缓存
def clear():
cmd='rm ./bin/*.*'
os.system(cmd)
cmd='rm ./gen/*.*'
os.system(cmd)
cmd='rm ../AoTeManLib/bin/*.*'
os.system(cmd)
cmd='rm ../AoTeManLib/gen/*.*'
os.system(cmd)
def startBuild():
clear()
with open('config.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
#print row['Name'], row['Package'],row['APPID'],row['APPKey'],row['Channel']
doBuildAPK(row)
csvfile.close()
startBuild()
相关文章推荐
- Android apk编译,打包过程详解及个人心得,附上java+doc写的自动化批量打包代码
- android自动化打包,只在编译打包时更改包名packagename
- windows下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件
- linux(以ubuntu为例)下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件
- linux(以ubuntu为例)下Android利用ant自动编译、修改配置文件、批量多渠道,打包生
- Android 自动编译、打包生成apk文件 4 - 多渠道批量打包
- windows下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件
- 将你的Android编译打包签名自动化
- Android学习系列(31)--App自动化之使用Ant编译项目多渠道打包
- Android笔记之:App自动化之使用Ant编译项目多渠道打包的使用详解
- Mac下android工程编译,批量打包的一些总结
- Android笔记之:App自动化之使用Ant编译项目多渠道打包的使用详解
- Ant自动化打多渠道包,Android批量打包提速
- Android批量打渠道包提速 - 1分钟900个市场不是梦(无须重新编译无须重新签名无须重新打包)
- android 下用ant编译脚本执行批量渠道打包
- Ant自动化打多渠道包,Android批量打包提速
- [转]Android学习系列(31)--App自动化之使用Ant编译项目多渠道打包
- windows下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件
- linux(以ubuntu为例)下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件
- Android App自动化之使用Ant编译项目多渠道打包