Building Xcode iOS projects and creating *.ipa file from the command line

For our development process of iOS applications, we are using Jenkins set up on the Mac Mini Server, acting as a Continuous Integration (CI) server. It’s fairly easy to configure Jenkins for Xcode projects using Xcode Plugin - however, from time to time we had some issues with setting it up correctly. In order to debug them, we’ve decided to include small shell scripts that build our iPhone and iPad apps – to compare results between our development machines and CI environment.

With introduction of the Xcode 6, building apps from command line became more important for us. For some reason, Xcode 6 requires signing into the Apple Developer account while exporting iOS binaries (*.ipa files). It means that you can no longer export binaries from the Xcode having just provisioning profile and matching certificate, or do that without internet connection. However, you can do it easily with command line tools!

If needed, you can find some more information about building the Xcode projects from command line on man pages (man xcodebuild) or on Building from the Command Line with Xcode FAQ page from the Apple resources.

Installing command line tools

First of all, install Xcode command line tool if you haven’t done that yet. Just follow steps from excellent tutorial on osxdaily, or just open your favourite terminal app and type:

xcode-select --install

This command should open pop up – just click on ‘Install’ button to continue.

Building Xcode projects (*.xcodeproj file) from the command line

Let’s assume you have project named BestAppEver, freshly created with recent version of the Xcode. Navigate to the directory where *.xcodeproj file is located and, as a first step, let’s create *.xcarchive file:

xcodebuild -scheme BestAppEver clean archive -archivePath build/BestAppEver

By default, xcodebuild will choose *.xcdoeproj project form current directory. However, you must specify scheme – if you haven’t changed anything, it will have same name as a project has. That’s -scheme BestAppEver part. Next, we specify what should be done – here we first clean up with clean action, and then archive project – specified by -archivePath build/BestAppEver part.

Next step – create *.ipa file:

xcodebuild -exportArchive -exportFormat ipa -archivePath "build/BestAppEver.xcarchive" -exportPath "build/BestAppEver.ipa" -exportProvisioningProfile "ProvisioningProfileName"

Here we specify that we want to export the *.ipa file  (-exportArchive -exportFormat ipa does this job), from the archive we created in previous step (-archivePath “build/BestAppEver.xcarchive”to a file in build sub-directory (-exportPath “build/BestAppEver.ipa”), with a selected provisioning profile (-exportProvisioningProfile “ProvisioningProfileName”).

I’m often wrapping this commands in a handy build.sh shell script:

#!/bin/sh
xcodebuild -scheme BestAppEver clean archive -archivePath build/BestAppEver
xcodebuild -exportArchive -exportFormat ipa -archivePath "build/BestAppEver.xcarchive" -exportPath "build/BestAppEver.ipa" -exportProvisioningProfile "ProvisioningProfileName"

Building Xcode workspaces (*.xcworkspace file) from the command line

Of course, most of our projects nowdays are using dependencies managed via cocoapods tool. It means that we should specify which workspace we want to use during creation of an archive file – to do that, add -workspace BestAppEver.xcworkspace switch to the first command. Our build.sh script would then have following content:

#!/bin/sh
xcodebuild -scheme BestAppEver -workspace BestAppEver.xcworkspace clean archive -archivePath build/BestAppEver
xcodebuild -exportArchive -exportFormat ipa -archivePath "build/BestAppEver.xcarchive" -exportPath "build/BestAppEver.ipa" -exportProvisioningProfile "ProvisioningProfileName"

I’m often adding pod install just above first xcodebuild  command.

BTW, this post was inspired by the response I’ve got on StackOverflowfor quoestion “Make Ad-hoc builds in Xcode 6 without signing in to developer account”.

时间: 2024-10-26 22:48:27

Building Xcode iOS projects and creating *.ipa file from the command line的相关文章

Accept Xcode/iOS License to run git

在没有安装Xcode的情况下, 使用了 webstorm 的git,提示 安装xcode,安装完成后,并没有打开xcode,而是再次使用git,发现 提示 输入以下命令行: sudo xcodebuild -license Agreeing to the Xcode/iOS license requires admin privileges, please re-run the command. 意思就是说,虽然安装了Xcode,但是并没有同意使用协议之类的,需要同意协议后,再次运行git相关命

How to build .apk file from command line(转)

How to build .apk file from command line Created on Wednesday, 29 June 2011 14:32 If you don’t want to install a number of programs for building your Android project, this article is for you. You will need only JDK, the Android SDK platform tools and

Unity3D研究院之IOS全自动打包生成ipa

接着上一篇文章, 自动生成framework,这篇文章我把shell自动化打包ipa整理了一下,希望大家喜欢,嘿嘿.. 建议大家先看一下上一篇文章.http://www.xuanyusong.com/archives/2720 首先我们要先搞清楚nity全自动打包的重要步骤. 1.自动生成xcode工程. 2.自动生成.ipa和dsym文件. 3.上传appstore(本篇略) 首先我们在做渠道包时,一般每个渠道都有自己一些特殊的需求,比如 游戏名子 .游戏图标.SDK.等等.那么我在在做自动化

Building QT projects from the command line

/************************************************************************ * Building QT projects from the command line * 说明: * 很多时候都是通过Qtcreator进行项目的创建以及编译,但是有时候可能 * 会遇到一些编译小问题,这时候命令行创建工程.编译工程可以作为测试.验证 * 的一种手段. * * 2016-3-2 深圳 南山平山村 曾剑锋 *************

ios命令行打IPA包(shenzhen)

利用github上一个开源项目:https://github.com/nomad/shenzhen可以在命令行为ios项目进行打包并发布. 具体安装步骤如下: gem install shenzhen 如果安装过程出现错误有可能是ruby的源找不到,可以到http://ruby.taobao.org/改变ruby源 如果还是出现问题可以更新下gem即可(sudo gem update). 一切准备完毕就能在控制台上运行ipa命令了: ipa Build and distribute iOS ap

ios如何免费打包ipa

正常操作是:xcode按部就班打包ipa,但需要申请苹果开发者账号(交钱,一年$99==¥688) 不正常操作如下: 假设你已经有了一个不报错的工程 步骤: 1.打包ios app并生成ipa(iphone可识别安装包) 2.将ipa装载到iphone上 —— 完 —— 原文地址:https://www.cnblogs.com/bbcfive/p/11022780.html

Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo

更新了xcode后使用goland运行项目时提示 Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo 更具提示打开xcode 点击agree安装即可!

Xcode 4-PBXcp error修复-No such file or directory

本文主要参考Xcode 4-PBXcp error修复-No such file or directory,并做了一些更新. 接手了一个新项目,真机编译时总是提示"PBXcp error-No such file or directory"这个错误,就是看了上面的文章也没解决问题,几经搜索,终于解决. 原因之一是因为上面文章方法3中说的,targets-build phases的copy bundle resources下有红色资源文件,而红色资源文件恰恰是main.storyboar

Unity3d导入工程出现错误“Creating unique file”的解决方法

Unity3d导入工程出现错误"Creating unique file:creating file Temp/tempFile failed.Please ensure there is enough disk space and you have permissions setup correctly". 解决方法:路径中有中文字符,把中文字符改成英文就可以了. 因路径路径有中文而出错的现象很多,如果出现导入错误,不妨看看路径是否有问题.