博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[原]Android打包之跨平台打包
阅读量:6719 次
发布时间:2019-06-25

本文共 3504 字,大约阅读时间需要 11 分钟。

Android自动打包流程详细图:

在前面一些博客我们知道了如何通过命令行打包,如何通过Eclipse打包,如何通过编写shell脚本来进行打包,但是这些都不能很好的跨平台进行打包。

因Python本身具有很好的跨平台特性,故本博就是通过使用Python来进行编写跨平台打包脚本,脚本如下(build.py):

#!/bin/python# build Android application package (.apk) from the command line using the SDK toolsimport osimport reimport sysimport timeimport shutilimport hashlibbuild_root = os.path.dirname(os.path.abspath('__file__'))build_source_name = 'source'build_apk_name = 'FullscreenActivity-release.apk'release_apk_path = build_root + '/release_apks'publish_apks = build_root + '/publish_apks'android_sdk = os.environ.get('ANDROID_SDK')build_tool_ant_path = android_sdk + '/tools/ant'build_bin_path = 'bin'build_bin_classes_path = 'classes'source_dir = build_root + '/' + build_source_name    rev_cmd = "svn info"rev_pattern = r"Last Changed Rev: ([0-9]*)"# delete file folderdef delete_file_folder(src):    if os.path.isfile(src):        try:            os.remove(src)        except:            pass    elif os.path.isdir(src):        for item in os.listdir(src):            itemsrc = os.path.join(src,item)            delete_file_folder(itemsrc)         try:            os.rmdir(src)        except:            pass# calc file md5def calcMD5(filepath):    with open(filepath,'rb') as f:        md5obj = hashlib.md5()        md5obj.update(f.read())        hash = md5obj.hexdigest()        return hash# get source code from svn Repositorydef get_source_code():    if (os.path.exists(release_apk_path)):        print release_apk_path + ' exists!'    else:        os.makedirs(release_apk_path)           if (os.path.exists(source_dir)):        os.chdir(source_dir)        os.system('svn update')    else:        os.makedirs(source_dir)        os.chdir(source_dir)        os.system('svn checkout https://github.com/clarck/AutoBuildProject/trunk .')# clear classes file folderdef clear_classes_folder():    classes_abs_path = source_dir + '/' + build_bin_classes_path    if (os.path.exists(classes_abs_path)):        delete_file_folder(classes_abs_path)    else:        os.makedirs(classes_abs_path) # get svn revisiondef get_revision():    rev = os.popen(rev_cmd).read()    m = re.search(rev_pattern, rev)    if m == None:        return None    return m.group(1)# get current timedef get_time():    return time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time.time()))# ant builddef ant_build():    os.system('android update project -p . --target android-19')    os.system('ant clean & ant release')# copy apk file to target folderdef copy_apk():    apk_file = source_dir + '/' + build_bin_path + '/' + build_apk_name    target_apk_file = release_apk_path + '/' + build_apk_name    if (os.path.exists(apk_file)):        shutil.copyfile(apk_file, target_apk_file)    else:        print apk_file + ' is not exists!'# delete source code filesdef delete_source_file():    delete_file_folder(source_dir)# publish apk def publish(date, rev):    if (os.path.exists(publish_apks)):        print publish_apks + ' exists!'    else:        os.makedirs(publish_apks)    md5 = calcMD5(release_apk_path + '/' + build_apk_name)    apk_file = release_apk_path + '/' + build_apk_name    publish_file = publish_apks + '/' + date + '_' + rev + '_' + 'release.apk'    shutil.move(apk_file, publish_file)    delete_file_folder(release_apk_path)# main function def main():    get_source_code()    clear_classes_folder()    rev = get_revision()    date = get_time()    ant_build()    copy_apk()    publish(date, rev)    if __name__ == '__main__':    main()

 

最后执行:python build.py即可。

转载地址:http://rdcmo.baihongyu.com/

你可能感兴趣的文章
【CSS】之选择器性能和规范
查看>>
如何在程序中使用官方汉化文件
查看>>
C#笔记
查看>>
数据库增删改查最简单练习
查看>>
马走日 题解
查看>>
卷积神经网络CNN的意义
查看>>
webstorm验证码
查看>>
繁简中文转换
查看>>
f5电源模块损坏
查看>>
RabbitMQ学习(五)_Hello World
查看>>
Silverlight DataGrid标题行居中
查看>>
Solr6 Suggest(智能提示)
查看>>
网页通用的测试用例
查看>>
Docker的容器创建以及基本命令
查看>>
BETA 版冲刺前准备
查看>>
转:最小区间:k个有序的数组,找到最小区间使k个数组中每个数组至少有一个数在区间中...
查看>>
LeetCode:Word Search
查看>>
DAY2-j打卡第二天2018-1-10
查看>>
2017-2018-2 20179209《网络攻防》第七周作业
查看>>
JavaScript--------从理解这些图开始
查看>>