How to build iOS project with command?

xcodebuild tutorial

Mark
2 min readJul 12, 2018

Before start the tutorial, we assume you are using pod to manage your iOS project and the project uses the following configuration.

Project name: Bookshop.xcodeproj
Workspace name: Bookshop.workspace
Build Configurations: Debug and Release
Targets: bookshop_dev and bookshop_release
Schemes:
bookshop_dev_scheme and bookshop_appStore_scheme.
The Build, Run, Test and Analyze are using Debug configuration. The Profile and Archive are using Release configuration. Each of the scheme only includes 1 related target.

Read xcodebuild action list and how to use the cmd

man xcodebuild or xcodebuild -help

List Project or Workspace Targets, Build Configuration and Schemes

xcodebuild -list

Clean Project or Workspace with scheme

xcodebuild clean -workspace Bookshop.xcworkspace -scheme bookshop_dev_schemexcodebuild clean -project Bookshop.xcodeproj -scheme bookshop_dev_scheme

Build Workspace with scheme

xcodebuild build -workspace Bookshop.xcworkspace -scheme bookshop_dev_scheme

build keyword is optional here. The default action of xcodebuild is build.

Archive Workspace

xcodebuild archive -workspace Bookshop.xcworkspace -scheme bookshop_dev_scheme -archivePath ~/Downloads/bookshop_dev.xcarchive

Create an ipa

xcodebuild -exportArchive -archivePath ~/Downloads/bookshop_dev.scarchive -exportPath ~/Downloads -exportOptionsPlist ~/Downloads/ExportOptions.plist

but, what should I put inside ExportOptions.plist?

What is ExportOptions.plist?

ExportOptions.plist is required in Xcode 9. It lets you to specify some options when you create an ipa file. You can select the options in a friendly UI when you use Xcode to archive your app. (you can copy and paste the file at the end of this article.)

Refer to <key>method</key> in ExportOptions.plist
Refer to <key>compileBitcode</key> and <key>thinning</key> in ExportOptions.plist
Refer to <key>signingStyle</key> in ExportOptions.plist, it uses manual signing

Example of ExportOptions.plist

Below lists down 2 exportOptions.plist. The first one is automatic signing, the second one is manual signing. For the manual signing, you need to login to your Apple Developer account to check the name of different certifications and provisioning profile.

Automatic Signing

Manual Signing

--

--