为什么

打包一般使用GUI操作进行。但是对于复杂工程还是繁琐。比如同一个工程对应多个target,多个scheme,多个证书。另外对于持续化集成还不足够,所以需要使用Xcodebuild进行脚本化。

Tips:针对Xcode进行过重签名,in-house包会失败。
使用

以下针对xcode8,xcworkspace文件进行打包。
简单来说打包分为三步:

1、 清理 - clean

xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme

2、 归档 - archive

xcodebuild archive -workspace MyWorkspace.xcworkspace -scheme MyScheme

3、 导出 - export

 xcodebuild -exportArchive -archivePath MyMobileApp.xcarchive -exportPath ExportDestination -exportOptionsPlist 'exportPlist.plist'

需要参数

@required

bundle_identifier
development_team
code_sign_identity
provisioning_profile

@optional

app_group
extension_bundle_identifier
extension_provisioning_profile

相关问题

  • 多环境

1、PROJECT -> Info -> Configurations 中添加configuration。
2、PROJECT -> Build Settings -> Preprocessor Macros 中添加宏。
如:DEBUG_LOG=1
3、在代码中判断宏,配置不同环境变量:

#ifdef DEBUG_LOG
#endif

4、增加scheme对应configuration。
5、针对scheme打包即是针对环境打包。

  • 多工程

一个工程对应一个scheme,针对scheme打包即是针对工程打包。

  • 不同证书

打包时设置bundle_identifier、development_team、code_sign_identity、provisioning_profile等参数即可。

  • 导出命令失败
error: exportArchive: No applicable devices found.
Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices found." UserInfo={NSLocalizedDescription=No applicable devices found.}** EXPORT FAILED **

解决方案:将xcodebuild替换为xcbuild.sh。xcbuild.sh如下:

#!/usr/bin/env bash --login
[[ -s "$HOME/.rvm/scripts/rvm"  ]] && source "$HOME/.rvm/scripts/rvm"
rvm use system
xcodebuild "$@"
  • exportPlist相关参数

简单来说method中enterprise为企业包,app-store为App Store发布包。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>method</key> <string>app-store</string> <key>uploadBitcode</key> <false/> <key>uploadSymbols</key> <false/> </dict>
</plist>

对应参数详情

Available keys for -exportOptionsPlist:compileBitcode : BoolFor non-App Store exports, should Xcode re-compile the app from bitcode? Defaults to YES.embedOnDemandResourcesAssetPacksInBundle : BoolFor 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.iCloudContainerEnvironmentFor 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 : DictionaryFor 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 : StringDescribes how Xcode should export the archive. Available options: app-store, ad-hoc, package, enterprise, development, and developer-id. The list of options varies based on the type of archive. Defaults to development. onDemandResourcesAssetPacksBaseURL : StringFor 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 : StringThe Developer Portal team to use for this export. Defaults to the team used to build the archive.thinning : StringFor 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 : BoolFor App Store exports, should the package include bitcode? Defaults to YES.uploadSymbols : BoolFor App Store exports, should the package include symbols? Defaults to YES.
  • 设置plist

使用/usr/libexec/PlistBuddy命令,可进行增删查改,如:

/usr/libexec/PlistBuddy -c 'Set :method "app-store"' exportPlist.plist
  • extension打包

包含extension的项目,需要指定多个provisioning_profile。以下步骤适用于主工程和extension工程:

1、手动选择证书

2、Build Settings -> Product Bundle Identifier -> 清空release对应的value

3、Build Settings -> Provisioning Profile -> release对应的value改为$APP_PROFILE(extension改为$EXTENSION_PROFILE)`

tips:APP_PROFILE、EXTENSION_PROFILE均可自定义,如extension有多个自行改名区分。
打包的归档部分修改如下:

xcodebuild archive -workspace MyWorkspace.xcworkspace -scheme MyScheme DEVELOPMENT_TEAM=${development_team} CODE_SIGN_IDENTITY=${code_sign_identity} APP_PROFILE=${provisioning_profile}  EXTENSION_PROFILE=${extension_provisioning_profile}

总结

脚本如下:

ios-build.sh

buildPath="yourbuildPath"
scheme="yourscheme"
package="yourpackage"
develop_team="yourdevelop_team"
code_sign_identity="yourcode_sign_identity"
provisioning_profile="yourprovisioning_profile"extension_provisioning_profile="yourextension_provisioning_profile"./xcbuild.sh clean -workspace ${package}.xcworkspace -scheme ${scheme}./xcbuild.sh archive -workspace ${package}.xcworkspace -scheme ${scheme} -archivePath "${buildPath}/${package}.xcarchive" DEVELOPMENT_TEAM=${develop_team} CODE_SIGN_IDENTITY=${code_sign_identity} APP_PROFILE=${provisioning_profile} EXTENSION_PROFILE=${extension_provisioning_profile} ./xcbuild.sh -exportArchive -archivePath "${buildPath}/${package}.xcarchive" -exportPath "${buildPath}/${package}" -exportOptionsPlist exportPlist.plist

xcbuild.sh

#!/usr/bin/env bash --login
[[ -s "$HOME/.rvm/scripts/rvm"  ]] && source "$HOME/.rvm/scripts/rvm"
rvm use system
xcodebuild "$@"

exportPlist.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict><key>method</key><string>app-store</string><key>uploadBitcode</key><false/><key>uploadSymbols</key><false/>
</dict>
</plist>

摘录

http://www.cocoachina.com/ios/20151104/14050.html
http://help.apple.com/xcode/mac/8.3/#/dev04b3a04ba

https://developer.apple.com/legacy/library/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/0-Introduction/introduction.html

http://stackoverflow.com/questions/27973011/xcodebuild-different-provisioning-profile-for-target-dependency

http://www.matrixprojects.net/p/xcodebuild-export-options-plist/
http://www.matrixprojects.net/p/xcodebuild-export-options-plist/

http://mjtsai.com/blog/2016/06/22/xcode-8-tips-and-issues/

http://stackoverflow.com/questions/27445649/xctool-build-with-today-extension

http://www.jianshu.com/p/1cec79a7ab46
https://wearebase.com/blog/2016/provisioning-and-distributing-watchkit-apps/

http://www.it1me.com/it-answers?id=2664885&s=AD&ttl=Xcode+%26quot%3BBuild+and+Archive%26quot%3B+from+command+line

https://pewpewthespells.com/blog/migrating_code_signing.html
---------------------
作者:xingshao1990
来源:CSDN
原文:https://blog.csdn.net/a184251289/article/details/71272002
版权声明:本文为博主原创文章,转载请附上博文链接!

iOS持续集成-Xcodebuild命令相关推荐

  1. 使用 fastlane 实现 iOS 持续集成

    使用 fastlane 实现 iOS 持续集成 2015-09-16 09:06 编辑: suiling 分类:iOS开发 来源:everettjf  0 3494 iOSfastlane持续集成 招 ...

  2. 构建iOS持续集成平台

    之前写的关于iOS持续集成平台的文章终于在infoQ上发表了,传送门: 自动化构建和依赖管理篇:[url]http://www.infoq.com/cn/articles/build-ios-cont ...

  3. CI Weekly #21 | iOS 持续集成快速入门指南

    搭建 iOS 持续集成环境要多久?每个 iOSer 都有不同的答案.这次我们整理了 flow.ci 的 iOS 持续集成的相关文档和最佳实践,希望帮你更快地完成构建.更新文档见: flow.ci iO ...

  4. 构建iOS持续集成平台(三)——CI服务器与自动化部署

    http://www.infoq.com/cn/articles/build-ios-continuous-integration-platform-part3 CI服务器 写到这儿,对于iOS开发者 ...

  5. 构建iOS持续集成平台(二)——测试框架

    [原文地址:http://www.infoq.com/cn/articles/build-ios-continuous-integration-platform-part2#0-tsina-1-332 ...

  6. 基于Jenkins搭建iOS持续集成开发环境

    原创 2017-03-06 关键点 Jenkins安装及配置 Pipeline创建及配置 ruby的版本管理工具rbenv安装 fastlane安装 常见构建问题 相关工具及技术网站推荐 CI持续集成 ...

  7. 【iOS】史上最全的iOS持续集成教程 (上)

    这个系列的博客分为上下两篇,上篇介绍命令行工具使用,下篇介绍利用Jenkins进行持续化集成 在iOS的开发过程中总是免不了要不停的打包,通常的打包方式是这样的 XCode->Archive-& ...

  8. 【网易严选】iOS持续集成打包(Jenkins+fastlane+nginx)

    本文来自网易云社区 作者:孙娇 严选iOS客户端的现有打包方式是通过远程连接打包机执行脚本去打包,打完包会输出相应的ipa的二维码,扫一扫二维码可以安装,但是随着测试队伍的壮大,外包同学越来越多,在打 ...

  9. 使用 fastlane 实现 iOS 持续集成(二)

    本文接上篇文章主要说下怎样使用 fastlane 上传到fir和蒲公英,下面先介绍下 plugin 命令. plugin命令介绍: 列出所有可用插件 fastlane search_plugins 搜 ...

最新文章

  1. xml xslt中的空格输出处理
  2. 吴恩达《Machine Learning》精炼笔记 9:PCA 及其 Python 实现
  3. 杨清彦:《像三国》游戏3D动效制作经验分享
  4. vertx rest 跨域_Vertx编程风格:您的React式Web Companion REST API解释了
  5. jquery-基础事件[下]
  6. DFS:C 小Y的难题(1)
  7. iOS 5 编程(1)-图像视图、滑块和步进控件的使用(源码下载)
  8. long long _int64使用总结
  9. javascript 的位操作符转换推断
  10. C++ hash(STL hash)及其函数模板用法详解
  11. java内网环境使用代理访问外网api
  12. 【数学建模】【lingo】lingo的基本操作
  13. Abaqus之地应力平衡分析步 Geostatic step
  14. 如何用计算机画地形地貌图,地形图是如何绘制出来的
  15. 如何利用python计算即期利率_即期利率的定义_即期利率的计算公式_即期利率和远期利率...
  16. C# Word 文档保护
  17. java加密方案:Virbox Protector Java版-全新保护方案
  18. docker之安装jdk8
  19. html文件设置成mac屏保,如何将视频设置为Mac上的屏幕保护程序 | MOS86
  20. 重庆大学非全日制计算机专业,2018年重庆大学非全日制研究生招生专业目录

热门文章

  1. Photoshop蒙版投射
  2. Pycharm 控制台如何打印出蓝色链接
  3. ipad手写笔有没有必要买?超实用的平板电脑手写笔推荐
  4. 小程序 绘制饼状图
  5. YouTuBe各类优秀频道推荐二音乐舞蹈
  6. JavaScript内存泄露,闭包内存泄露如何解决
  7. 【MySQL】基于MySQL的SQL优化(二)——对count()、max()的优化
  8. Emacs教程(一)
  9. 【肖广老师 银行绩效提升专家】
  10. mysql与mongo数据库的优缺点比较