views:

2412

answers:

5

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

  1. 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.
  2. 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.

A: 

Go to the folder where's your project root and:

xcodebuild -project projectname -activetarget -activeconfiguration archive
erick2red
This doesn't seem to work. The 'archive' buildaction isn't available in XCode 3.2.2 (final).
Martin Cote
archive action not supported
lyxera
+6  A: 

I've been using my own build script to generate the ipa package for ad hoc distribution.

die() {
    echo "$*" >&2
    exit 1
}

appname='AppName'
config='Ad Hoc Distribution'
sdk='iphoneos3.1.3'
project_dir=$(pwd)

echo using configuration $config

echo updating version number
agvtool bump -all
fullversion="$(agvtool mvers -terse1)($(agvtool vers -terse))"
echo building version $fullversion

xcodebuild -activetarget -configuration "$config" -sdk $sdk build || die "build failed"

echo making ipa...
# packaging
cd build/"$config"-iphoneos || die "no such directory"
rm -rf Payload
rm -f "$appname".*.ipa
mkdir Payload
cp -Rp "$appname.app" Payload/
if [ -f "$project_dir"/iTunesArtwork ] ; then
    cp -f "$project_dir"/iTunesArtwork Payload/iTunesArtwork
fi

ipaname="$appname.$fullversion.$(date -u +%Y%m%d%H%M%S).ipa"
zip -r $ipaname Payload

echo finished making $ipaname

The script also increment the version number. You can remove that part if it's not needed. Hope it helps.

Arrix
This is a good solution, although your code is a bit hard to read without comments. Would you write a bit more about what's happening?
Michael Grinich
+1  A: 

I tried to understand what this command was doing by diffing a normally generated ipa and an ipa generated via the "Build and Archive" Xcode menu. Didn't see any useful difference.

If it produce the same files, how come one of them doesn't require beta testers to first install an external mobile provisioning profile first?

Guillaume
I think iTunes may treat IPA files differently than just imported .app files. In Xcode 3.2.3, all Ad-Hoc builds include an embedded provisioning profile.
Michael Grinich
I compared two ipas, one generated by Xcode, one manually created. I couldn't see what was different, yet one was treated differently (didn't require to install the provisioning profile manually).
Guillaume
A: 

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.

Michael Grinich
I clarified my question. When you say "I can" above, do you mean you can actually do this today?
Dan Fabulich
Yes. I'm using [Hudson Continuous Integration](http://hudson-ci.org/) with a custom script which runs `xcodebuild` and makes an IPA.
Michael Grinich
A: 

Although the produced .ipa works just fine with iTunes, the iPhone Configuration Utility is complaining about the iTunesArtwork file not having an extension. I was under the impression that including it in the xcode project to be copied along with other resources is the current correct practice. Any thoughts?

Scott Marks