利用xcodebuild命令导出ipa包,并签名

来源:互联网 发布:网络域名申请 编辑:程序博客网 时间:2024/06/05 09:32

最近由于需要接很多渠道,用xcode手动打包太麻烦,就用python写了工具用于导出ipa包,功能比较简单,代码贡献出来。
使用方法:

python ipaExport.py -m /Users/xxxx/AdHoc.mobileprovision -s "iPhone Distribution: xxx.\ \(YV5J8U46A2\)" -t xxxIOS -c "Ad\ hoc"

-m 证书文件的路径
-s 对应的签名 已经安装在电脑上的 字符串有空格需要转义
-c 打包类型 ‘Ad\ hoc’是我自己定义用来打包inhouse的,项目有自带的Release和Debug,一般Release的包需要上传到AppStore我是不通过命令打包的,Debug也不太需要,所以默认我就写了Ad hoc,参数如果有空格需要转义一下
-t target类型 一般基本上就是项目名称,看你xcode里面的配置

需要注意的是路径最好不要有空格,我默认将ipa包输出到build文件夹,并且以target+打包类型.ipa!!!

新建一个文件名称为ipaExport.py文件,把下面代码粘贴进去

#! -*- coding: utf8 -*-import osimport subprocessimport sysimport argparse# pro_dir is ios xxx.xcodeproj 目录 这是我当前的python文件目录算出来的项目目录 需要手动修改为你的项目的目录 可以写成绝对路径pro_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../proj.ios'))# sign 签名名称# profilePath 证书路径def build(target,sign,profile,config):    print 'sign is:'+sign    print 'profile:'+profile    print "开始清理!"    command = "cd %s; xcodebuild -target %s clean "% (pro_dir,target)    os.system(command)    print "编译!"    command = "cd %s;xcodebuild -target %s  -sdk iphoneos -configuration %s" % (pro_dir,target,config)    os.system(command)    ipa_out_put = os.path.join(pro_dir,"build/%s_%s.ipa"%(target,config))        print "打包ipa!输出到 %s" % ipa_out_put        command = "cd %s;xcrun -sdk iphoneos PackageApplication -v build/%s-iphoneos/%s.app -o '%s' —sign %s  —embed %s" % (pro_dir,config,target,ipa_out_put,sign,profile)        print command        os.system(command)if __name__ == '__main__':    parser = argparse.ArgumentParser(description='Process args')    #证书路径    parser.add_argument('-m', '--profile', help='mobileprovision file path 证书路径 不能为空')    #签名    parser.add_argument('-s', '--sign', help='installed sign 电脑上已经安装的签名 不能为空')    #项目的target    parser.add_argument('-t', '--target', help='target name 项目的target 不能为空')    #Release Debug Or AdHoc等 默认为AdHoc    parser.add_argument('-c','--config',help='target type 默认为 Ad\ hoc')    args = parser.parse_args()    if args.profile==None:        print "请设置-m 证书路径"    if args.sign==None:        print "请设置-s 签名 例如:'iPhone Distribution: xxxx. (YV5J8U46A2)'"    if args.target==None:        print "请设置-t target"    if args.config==None:        args.config = "Ad\ hoc"        print "没有设置 -c 配置 默认为 Ad\ hoc"    if args.profile and args.sign and args.target and args.config:        build(args.target,args.sign,args.profile,args.config)
0 0
原创粉丝点击