What this guide covers
When you finish, you have archive and export commands you can run repeatedly, and an export options file committed to the repository. You need: Xcode installed, a project that builds normally in the interface, and usable signing material.
Steps
First confirm what the project contains
xcodebuild -list -workspace App.xcworkspaceThis lists the schemes in the workspace. Projects that use CocoaPods take
-workspace; otherwise use-project App.xcodeproj. The scheme you archive must be shared (present in the repository), or it will not be found on another machine.Archive
xcodebuild archive -workspace App.xcworkspace -scheme App -configuration Release -destination generic/platform=iOS -archivePath build/App.xcarchiveBoth the
archiveaction and thegeneric/platform=iOSdestination form come from the manual that ships withxcodebuild.-archivePathsays where the archive goes; the export step needs it.For an automatically signed project on a machine with no signed-in account, add
-allowProvisioningUpdatesand the three API key options.Write an export options file
Exporting needs a plist file that says how to distribute. Run
xcodebuild -helpfor the full list of available keys. The common ones:method: the distribution method. The values listed in the help includeapp-store-connect,release-testing,enterprise,debuggingand others, and it notes that the olderapp-store,ad-hocanddevelopmentspellings are deprecated. The values change between Xcode versions, so go by the help output on your machine.destination:exportexports locally,uploaduploads straight to Apple; the default is export.signingStyle:automaticormanual.teamID: which team to export with.
Commit this file to the repository; it contains no secrets.
Export
xcodebuild -exportArchive -archivePath build/App.xcarchive -exportPath build/export -exportOptionsPlist ExportOptions.plistThe manual describes this as distributing the specified archive according to the export options; the product can be uploaded to Apple or exported to the location given by
-exportPath. Withdestinationset toexport, that directory will contain the ipa.If signing hangs, look at the keychain first
If it works in Terminal on the graphical desktop but hangs when run from a background service or a remote terminal, the system has most likely popped up a keychain authorization window during signing with nobody there to click it. See our guide on unlocking the keychain on a build machine for the fix; do not rely on retrying.
Running it on a remote Mac: inside tmux, with output to a log
A full archive takes a while. Run it straight in a Terminal window on the remote desktop and the job is gone as soon as the window closes. Put it in a tmux session and write the output to a file:
xcodebuild archive ... 2>&1 | tee build/archive.logSee how to keep long tasks running for details. Do not shut the machine down during a build; disconnecting the remote desktop does not stop it.
Take the build products with you
The ipa in
build/exportcan be deleted once uploaded, but the symbol files (dSYM) in the archive decide whether you can make sense of crash logs later. Upload each release's xcarchive, or the dSYMs inside it, to your own storage.This machine is reclaimed when the rental ends, and the Organizer's archive list does not come with you.
FAQ
Is a command-line archive the same as clicking Archive in Xcode?
With the same scheme and configuration, the products are equivalent. The main difference is signing: the interface pops up windows for you to confirm, while on the command line you have to prepare the account, key or keychain in advance.
Export fails saying no provisioning profile was found. What should I check?
With automatic signing, confirm you added -allowProvisioningUpdates and supplied an account or key. With manual signing, check that the Bundle ID and profile name under provisioningProfiles in the export options match.
Can the export step upload directly?
Yes, set destination to upload in the export options. For the authentication the upload needs, go by Apple's documentation and your Xcode version. You can also export the ipa first and upload it with altool or Transporter.
Do Flutter projects use these two commands too?
Flutter's own build command calls xcodebuild internally. Whether to use the framework's command or write these two by hand is a matter for the official Flutter documentation; the export options file works the same way either way.
Related
- Xcode automatic vs manual signing: which to use and how to set up each
- How to upload iOS builds with an App Store Connect API key, with no 2FA prompts
- Code signing hangs on a CI Mac: unlock the keychain or use a dedicated one
- How to keep long tasks running on a remote Mac mini after you disconnect
- Rented Mac mini as an always-on build machine for small teams? Count your build minutes first
Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support