Xcode 3.2 provides an awesome new feature under the Build menu, "Build and Archive" which generates an .ipa file suitable for Ad Hoc distribution. You can also open the Organizer, go to "Archived Applications," and "Submit Application to iTunesConnect."
Is there a way to use "Build and Archive" from the command line (as part of a build script)? I'd assume that xcodebuild
would be involved somehow, but the man
page doesn't seem to say anything about this.
UPDATE Michael Grinich requested clarification; here's what exactly you can't do with command-line builds, features you can ONLY do with Xcode's Organizer after you "Build and Archive."
- You can click "Share Application..." to share your IPA with beta testers. As Guillaume points out below, due to some Xcode magic, this IPA file does not require a separately distributed .mobileprovision file that beta testers need to install; that's magical. No command-line script can do it. For example, Arrix's script (submitted May 1) does not meet that requirement.
- More importantly, after you've beta tested a build, you can click "Submit Application to iTunes Connect" to submit that EXACT same build to Apple, the very binary you tested, without rebuilding it. That's impossible from the command line, because signing the app is part of the build process; you can sign bits for Ad Hoc beta testing OR you can sign them for submission to the App Store, but not both. No IPA built on the command-line can be beta tested on phones and then submitted directly to Apple.
I'd love for someone to come along and prove me wrong: both of these features work great in the Xcode GUI and cannot be replicated from the command line.
With Xcode 4.2 you can use the -scheme flag to do this:
After this command the Archive will show up in the Xcode Organizer.
The
xcodebuild
tool can build and export archive products with the -exportArchive flag (as of Xcode 5). The export step was previously only possible via the Xcode Organizer UI.First archive your app:
Given
$ARCHIVE_PATH
(the path to the .xcarchive file), export the app from the archive with one of the following:iOS .ipa file:
Mac .app file:
In both commands the -exportProvisioningProfile and -exportSigningIdentity arguments are optional.
man xcodebuild
for details on the semantics. In these examples, the provisioning profile for the iOS build specified an AdHoc distribution provisioning profile, and the signing identity for the Mac app specified a Developer ID for export as a 3rd party application (i.e. not distributed via the Mac App Store).We developed an iPad app with XCode 4.2.1 and wanted to integrate the build into our continuous integration (Jenkins) for OTA distribution. Here's the solution I came up with:
Then Jenkins uploads the ipa, plist and html files to our webserver.
This is the plist template:
To set this up, you have to import the distribution certificate and provisioning profile into the designated user's keychain.
For Xcode 7, you have a much simpler solution. The only extra work is that you have to create a configuration plist file for exporting archive.
(Compared to Xcode 6, in the results of
xcrun xcodebuild -help
,-exportFormat
and-exportProvisioningProfile
options are not mentioned any more; the former is deleted, and the latter is superseded by-exportOptionsPlist
.)Step 1, change directory to the folder including .xcodeproject or .xcworkspace file.
Step 2, use Xcode or
/usr/libexec/PlistBuddy exportOptions.plist
to create export options plist file. By the way,xcrun xcodebuild -help
will tell you what keys you have to insert to the plist file.Step 3, create .xcarchive file (folder, in fact) as follows(build/ directory will be automatically created by Xcode right now),
Step 4, export as .ipa file like this, which differs from Xcode6
Now, you get an ipa file in build/ directory. Just send it to apple App Store.
By the way, the ipa file created by Xcode 7 is much larger than by Xcode 6.
Xcode 8:
IPA Format:
Exports the archive MyMobileApp.xcarchive as an IPA file to the path MyMobileApp.ipa using the provisioning profile MyMobileApp Distribution Profile.
APP Format:
Exports the archive MyMacApp.xcarchive as a PKG file to the path MyMacApp.pkg using the appli-cation application cation signing identity Developer ID Application: My Team. The installer signing identity Developer ID Installer: My Team is implicitly used to sign the exported package.
Xcodebuild man page
After updating to Xcode 8, I found that enterprise ipa generate by
So I switch to
xcodebuild -exportArchive
and everything went back normal.