xcodebuild自动打包,发布应用

简介

在iOS持续集成的过程中,签名打包这一部分,就是对原生指令进行了封装, 将常用的参数名简化, 支持全部的自带参数及设置, 同时输出符号表 dSYM 文件, 并且支持直接从相关 repo 直接编译打包.因此熟悉一下xcodebuild还是很有必要的。

在终端输入man xcodebuild,可以看到Description里面有介绍用法。

打包流程

Archive包

xcodebuild archive -workspace 项目名称.xcworkspace 
                       -scheme 项目名称 
                       -configuration 构建配置 
                       -archivePath archive包存储路径 
                       CODE_SIGN_IDENTITY=证书 
                       PROVISIONING_PROFILE=描述文件UUID

在这里证书,和描述文件的字段,可要可不要,它会根据xcode去匹配

证书对应内容:
在钥匙串找到对应证书把加粗部分的标题复制出来即可

DEA480DF-1E62-427E-92A3-2D8556D5D63A.png

描述文件UUID:
首先到描述文件路径:

/Users/用户名/Library/MobileDevice/Provisioning Profiles 

在终端下解密描述文件

security cms -D -i xxxx.mobileprovision

可以找到TeamName,UUID,等对应的value值,注意要 在CODE_SIGN_IDENTITY,PROVISIONING_PROFILE赋值时要加“”号

DBD1245A-4FE3-4459-A548-3DAEE83916E9.png

导出ipa包

xcodebuild -exportArchive -archivePath archive文件的地址.xcarchive 
                          -exportPath 导出的文件夹地址 
                          -exportOptionsPlist exprotOptionsPlist.plist 
                          CODE_SIGN_IDENTITY=证书 
                          PROVISIONING_PROFILE=描述文件UUID

同样的,证书和描述文件的参数可要可不要,exportOptionsPlist是plist文件,我们可以用xcode创建一个,在里面可以配置参数,我的如下:

image.png

我的命令:

350A6141-A444-473F-8968-D0E00B0BF3EF.png

使用xcodebuild exportOptionsPlist -h 查看plist可写参数

Available keys for -exportOptionsPlist:

    compileBitcode : Bool

        For non-App Store exports, should Xcode re-compile the app from bitcode? Defaults to YES.

    embedOnDemandResourcesAssetPacksInBundle : Bool

        For non-App Store exports, if the app uses On Demand Resources and this is YES, asset packs are embedded in the app bundle so that the app can be tested without a server to host asset packs. Defaults to YES unless onDemandResourcesAssetPacksBaseURL is specified.

    iCloudContainerEnvironment

        For non-App Store exports, if the app is using CloudKit, this configures the "com.apple.developer.icloud-container-environment" entitlement. Available options: Development and Production. Defaults to Development.

    manifest : Dictionary

        For non-App Store exports, users can download your app over the web by opening your distribution manifest file in a web browser. To generate a distribution manifest, the value of this key should be a dictionary with three sub-keys: appURL, displayImageURL, fullSizeImageURL. The additional sub-key assetPackManifestURL is required when using on demand resources.

    method : String

        Describes how Xcode should export the archive. Available options: app-store, package, ad-hoc, enterprise, development, and developer-id. The list of options varies based on the type of archive. Defaults to development.

    onDemandResourcesAssetPacksBaseURL : String

        For non-App Store exports, if the app uses On Demand Resources and embedOnDemandResourcesAssetPacksInBundle isn't YES, this should be a base URL specifying where asset packs are going to be hosted. This configures the app to download asset packs from the specified URL.

    teamID : String

        The Developer Portal team to use for this export. Defaults to the team used to build the archive.

    thinning : String

        For non-App Store exports, should Xcode thin the package for one or more device variants? Available options: <none> (Xcode produces a non-thinned universal app), <thin-for-all-variants> (Xcode produces a universal app and all available thinned variants), or a model identifier for a specific device (e.g. "iPhone7,1"). Defaults to <none>.

    uploadBitcode : Bool

        For App Store exports, should the package include bitcode? Defaults to YES.

    uploadSymbols : Bool

        For App Store exports, should the package include symbols? Defaults to YES.

上传

1.测试包:

可以上传到fir,蒲公英等网站,以fir为例,
首先需要一个注册一个fir账号,从里面可以获取一个apitoken
安装fir(fir命令参考)

 ruby -v  // > 1.9.3
 gem install fir-cli

登录fir

fir login   //此时会让你输入apitoken
fir me  //获取账号信息

发布应用到fir

fir publish  ipa包全路径

发布成功后,终端会输出一个路径,这个就是应用发布后的路径,复制访问即可.

2.正式包

altool:Application Loader的命令行工具用来验证并上传你的应用程序二进制文件到App Store
altool工具路径:

/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool

设置别名

在~/.bash_profile 中设置别名
alias altool='/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool'

设置别名后在终端
输入 source ~/.bash_profile
再输入 altool  就会有它的一些用法提示,否则就是设置别名失败了 

altool用法

验证 ipa
altool --validate-app -f file -u username [-p password] [--output- format xml]
上传 ipa
altool --upload-app -f file -u username [-p password] [--output- format xml]

具体参数:

--validate-app
您要验证的应用程序。
--upload-app
您要上传的应用程序。
-f file
您正在验证或上传的应用程序的路径和文件名。
-u username
您的用户名。
-p password
您的用户密码。
--output-format [xml | normal]
您要 Application Loader 以结构化的 XML 格式还是非结构化的文本格式返回输出信息。Application Loader 默认以文本格式返回输出信息。

我的验证命令如下:

altool -validate-app -f 路径.ipa   -u  用户名  -p 密码 -t ios

不出意外就可以得到一个成功的验证结果,我用的是以前上架过的包,得到的验证是已经存在这个包的错误提示

屏幕快照 2017-08-29 下午2.46.35.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,117评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,328评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,839评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,007评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,384评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,629评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,880评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,593评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,313评论 1 243
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,575评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,066评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,392评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,052评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,082评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,844评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,662评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,575评论 2 270

推荐阅读更多精彩内容