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.
I found how to automate the build and archive process from the comand line, I just wrote a blog article explaining how you can achieve that.
The command you have to use is
xcrun
:You will find all the details in the article. If you have any questions dont hesitate to ask.
I found some of the other answers here hard to get going. This article did if for me. Some paths may need to be absolute, as mentioned in the other answers.
The Command:
Going one step further, uploading to iTunesConnect via commandline with Xcode 7! (Assuming you are starting with an
.ipa
that has been signed with the correct release profile and signing identity.)Enter
altool
, the CLI interface for the Application Loader (docs
, page 38). Hidden deep within Xcode.app's structure, is a handy function to let us upload directly to ItunesConnect.Simply run
$ altool --upload-app -f file -u username [-p password]
to upload your newly minted.ipa
straight to Apple. The password is optional, and will prompt you for it if you leave it off the command.If there are any issues with the app during the verification step, the console will print them out.
You will likely have to export the path to
altool
if you don't want to save its location.Thats it! Simply login to iTunesConnect.com and select your new build for testing with testflight.
Final Note: If you get an error saying
Exception while launching iTunesTransporter: Transporter not found at path: /usr/local/itms/bin/iTMSTransporter. You should reinstall the application
, you can follow the suggestion on this SO answer, to run a symlink to the correct location:You mean the validate/share/submit options? I think those are specific to Xcode, and not suited for a command-line build tool.
With some cleverness, I bet you could make a script to do it for you. It looks like they're just stored in
~/Library/MobileDevice/Archived Applications/
with a UUDI and a plist. I can't imagine it would be that hard to reverse engineer the validator either.The process I'm interested automating is sending builds to beta testers. (Since App Store submission happens infrequently, I don't mind doing it manually, especially since I often need to add new description text.) By doing a pseudo Build+Archive using Xcode's CLI, I can trigger automatic builds from every code commit, create IPA files with embedded provisioning profiles, and email it to testers.
I've been using my own build script to generate the ipa package for ad hoc distribution.
The script also increment the version number. You can remove that part if it's not needed. Hope it helps.
You CAN actually resign a build, just as XCode does, so that you can test and ship the same binary. For example in my script (similar to those above) I build my release version signed as an AdHoc build, then I archive that as an IPA for testing, then resign with my distribution cert and create a zip file, which is what I send to Apple. The relevant line is: