您的位置:首页 > 移动开发 > Android开发

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 主工程,执行命令

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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐