Home/Guides/How to archive and export an ipa from the command line with xcodebuild

How to archive and export an ipa from the command line with xcodebuild

Updated · airankrush

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

  1. First confirm what the project contains

    xcodebuild -list -workspace App.xcworkspace

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

  2. Archive

    xcodebuild archive -workspace App.xcworkspace -scheme App -configuration Release -destination generic/platform=iOS -archivePath build/App.xcarchive

    Both the archive action and the generic/platform=iOS destination form come from the manual that ships with xcodebuild. -archivePath says where the archive goes; the export step needs it.

    For an automatically signed project on a machine with no signed-in account, add -allowProvisioningUpdates and the three API key options.

  3. Write an export options file

    Exporting needs a plist file that says how to distribute. Run xcodebuild -help for the full list of available keys. The common ones:

    • method: the distribution method. The values listed in the help include app-store-connect, release-testing, enterprise, debugging and others, and it notes that the older app-store, ad-hoc and development spellings are deprecated. The values change between Xcode versions, so go by the help output on your machine.
    • destination: export exports locally, upload uploads straight to Apple; the default is export.
    • signingStyle: automatic or manual.
    • teamID: which team to export with.

    Commit this file to the repository; it contains no secrets.

  4. Export

    xcodebuild -exportArchive -archivePath build/App.xcarchive -exportPath build/export -exportOptionsPlist ExportOptions.plist

    The 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. With destination set to export, that directory will contain the ipa.

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

  6. 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.log

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

  7. Take the build products with you

    The ipa in build/export can 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.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All guides