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”.

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

  1. how to import a SQL file in MySQL command line

    how to import a SQL file in MySQL command line execute .sql file, macOS $mysql> source \home\user ...

  2. Accept Xcode/iOS License to run git

    在没有安装Xcode的情况下, 使用了 webstorm 的git,提示 安装xcode,安装完成后,并没有打开xcode,而是再次使用git,发现 提示 输入以下命令行: sudo xcodebui ...

  3. 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 ...

  4. 怎样安装Command Line Tools in OS x Mavericks&Yosemite(Without xcode)--转载

    How to Install Command Line Tools in OS X Mavericks & Yosemite (Without Xcode) Mac users who pre ...

  5. Yandex Big Data Essentials Week1 Unix Command Line Interface File Content exploration

    cat displays the contents of a file at the command line copies or apppend text file into a document ...

  6. NewRelicAgent(CustomAnalyticEvent.cxx.o), building for iOS simulator, but linking in object file built for OSX, for architecture x8(botched)

    昨天遇到一个问题,在项目swift1.2适配swift2.0的过程中,修改完毕之后,运行报错如下: /Pods/NewRelicAgent/NewRelic_iOS_Agent_5.1.0/NewRe ...

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

    接着上一篇文章, 自动生成framework,这篇文章我把shell自动化打包ipa整理了一下,希望大家喜欢,嘿嘿.. 建议大家先看一下上一篇文章.http://www.xuanyusong.com/ ...

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

    Xcode 4-PBXcp error修复-No such file or directory (2013-05-02 15:20:50) 转载▼ 标签: apple iphone ios 移动开发 ...

  9. Building QT projects from the command line

    /************************************************************************ * Building QT projects fro ...

随机推荐

  1. getHeight returns 0 for all Android UI objects

    It's 0 because in both onCreate and onStart, the view hasn't actually been drawn yet. You can get ar ...

  2. Cocos2D创建项目

    创建项目 配置好开发环境后, 用CMD切换到~\cocos2d\cocos2d-x-2.2.2\tools\project-creator目录上执行以下脚本 python create_project ...

  3. js获取对象、数组的实际长度,元素实际个数

    /*获取对象.数组的长度.元素个数 *@param obj 要计算长度的元素,可以为object.array.string */ function count(obj){ var objType = ...

  4. 使用Putty连接VirtualBox的Ubuntu

    从vbox中安装了ubuntu server,然后用ssh连过去,发现有一个错误:server unexpectedly closed network connection.猛然发现,ssh没有安装. ...

  5. jsp的<%@ include file="jsp/common.jsp" %>报错误Duplicate local variable basePath

    将公共引入的文件放到common.jsp中,其他页面引入该jsp即可使用 <%@ page language="java" import="java.util.*& ...

  6. VC6.0环境安装STLport-5.2.1

    今天安装STLport,网上搜资料安装好久,都不行,因为STLport 的版本不对,我这是STLport-5.2.1新版本. (注意:下面的步骤都在一个cmd里操作,很简单的原因:环境变量啊) 1.首 ...

  7. c#中HttpWebRequest使用Proxy实现指定IP的域名请求

    原文:http://www.cnblogs.com/greenerycn/archive/2010/04/11/httpwebreques_host_modify_By_set_proxy.html ...

  8. netbeans 7安装xdebug调试php程序

    1.下载安装xdebug 先从xdebug官网下载对应php版本的xdebug组件,下载地址是:http://www.xdebug.org/download.php 如果不确定下载哪个版本的xdebu ...

  9. Codeforces 337D Book of evil

    一道树形dp,写出来是因为最近也做了道类似的.这题是看了分析的思路才做出来的,但感觉很多这样的dp都是利用类似的性质.像这题的话distDown很好想,但distUp的时候就很难想了,其实只要抓住di ...

  10. zoj 3232 It's not Floyd Algorithm(强联通分量,缩点)

    题目 /******************************************************************/ 以下题解来自互联网:Juny的博客 思路核心:给你的闭包 ...