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

最近由于需要接很多渠道,用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 os
import subprocess
import sys
import 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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值