Build Automation With Xcode and IPA Hosting Using Visual Studio AppCenter
Using Xcode CLI to create build automation and upload scripts for your CI/CD or local machines.
Prerequisites
1. Latest version of Xcode (minimum 9.0+)
2. Your iOS project is managed with pods
3. Some knowledge of Bash (if you are working with a CI/CD)
4. An AppCenter account.
Lets, Dive into it
Using xcodebuild
xcodebuild
is the CLI command to invoke the build process and other utilities for xcode. To get detailed list of arguments available with it use:xcodebuild -help
Choosing Build vs Archive
If you have used xcode GUI to open up your workspace you must have seen the following options :
Before you execute your commands you need to learn the difference between Building a project vs Archiving it.
Build : It is your compilation of the source code to execute the project. This does not create a .dSYM
file, thus cannot be used for distribution purposes.
Archive : It is the complete package which contains your .app
and other related files. It generates a .xcarchive
directory which is then used to generate your .ipa
Since we would be generating an .ipa
in this tutorial we will be focusing on Archive
Listing you Schemes
xcodebuild -list -workspace YOURWORKSPACE.xcworkspace
Clean Project
From the list your received using the above command pick your required scheme.
xcodebuild clean -workspace YourWorkspace.xcworkspace -scheme YourScheme
Archiving the Workspace
At this point there are two ways you can handle your Code Signing problem :
1. Manual
Here we are required to have our Provisioning profile present on the system. This is a tedious way of managing the process and I advice using Automatic Code Signing if possible
xcodebuild archive -workspace YourWorkspace.xcworkspace -scheme YourScheme -archivePath PathWhereArchiveWillBeCreated PROVISIONING_PROFILE_SPECIFIER = "YourProvisioningProfile" CODE_SIGN_STYLE = "Manual" DEVELOPMENT_TEAM = YourDevTeamID
2. Automatic
Xcode (9+) also has a way to handle Code signing automatically which doesn’t require you to keep track of your profiles. You just need to be logged in with an account which has access to the application you are trying to build.
xcodebuild archive -workspace YourWorkspace.xcworkspace -scheme YourSceme -archivePath PathWhereArchiveWillBeCreated -allowProvisioningUpdates CODE_SIGN_STYLE = "Automatic" DEVELOPMENT_TEAM = YourDevTeamID
Generating IPA
Add your ExportOptionsPlist file
This is a configuration file which contains the settings required for generating .ipa
. Use the following as a sample for yours , Keep the indentation in mind while writing this:
Automatic
Manual
Once you have created your ExportOptionsPlist file, run the following to generate your .ipa
:
1. Manual
xcodebuild -exportArchive -archivePath PathWhereArchiveWasCreated -exportPath PathWhereIPAWillBeCreated -exportOptionsPlist YourPlist
2. Automatic
xcodebuild -exportArchive -archivePath PathWhereArchiveWasCreated -exportPath PathWhereIPAWillBeCreated -exportOptionsPlist YourPlist -allowProvisioningUpdates
Using AppCenter to Manage Your Builds
The .ipa
files generated cannot be sideloaded like their android counterparts, to solve this distribution issue you can use hosting portals like Bitrise, Appcenter etc to manage and distribute your apps before you put them on store. We will be discussing Visual Studio Appcenter as the option here.
Setup
- Install Appcenter Cli tools :
npm install -g appcenter-cli
- Login :
appcenter login
, Your browser would open up, copy thetoken
given there and close the browser - Paste the token in the terminal/cmd window. You will be now logged in. It is advisable to save this
token
to prevent going through the login procedure every time by appending it to all our commands.
Upload your IPA
- Add a new App on your Appcenter dashboard by clicking on the Add New button on top right corner, Make sure to setup the os as iOS.
You can receive a list of all your configured applications in format of owner/AppName
by running the following command :
appcenter apps list --token YourToken
2. Once you have your app created you have to add a Distribution group. You can also allow public access here if you want to.
3. Once The distribution group is created we can upload our .ipa
to the it, we can add custom arguments like Release notes etc. as well :
appcenter distribute release --app owner/AppName --file PathOfIPA --release-notes "Release Notes" --group DistributionGroup --token YourToken
More arguments for the cli can be found at the official Github page.
4. You can now install your app directly on your iOS device using the Install link for your Distribution Group given on your Dashboard