Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode "Build and Archive" from command line

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.

like image 347
Dan Fabulich Avatar asked Apr 19 '10 02:04

Dan Fabulich


People also ask

How do I archive an Xcode project in Terminal?

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

How do I build and archive in Xcode?

Archive your App In Xcode with your project open, select the simulator (button near the top of the window next to your project name, typically named as a specific type of iPhone) – change it to Generic iOS Device. Open the Product menu and choose Archive. You will see the archive information. Click Validate App.

What is the archive command in Xcode?

The Step archives your Xcode project by running the xcodebuild archive command and then exports the archive into an . ipa file with the xcodebuild -exportArchive command. This . ipa file can be shared, installed on test devices, or uploaded to the App Store Connect.

Do I need to build before archive Xcode?

Yes you are right, you dont required 'Build' before archiving. So, you can directly archive it(it automatically going to build it). This error comes when compiler unable to find required library. So, check your Runpath search paths ( Library search paths in xcode version older than iOS 12) in build settings.


2 Answers

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:

/usr/bin/xcrun -sdk iphoneos PackageApplication \ -v "${RELEASE_BUILDDIR}/${APPLICATION_NAME}.app" \ -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" \ --sign "${DEVELOPER_NAME}" \ --embed "${PROVISONING_PROFILE}" 

You will find all the details in the article. If you have any questions dont hesitate to ask.

like image 64
vdaubry Avatar answered Oct 21 '22 09:10

vdaubry


With Xcode 4.2 you can use the -scheme flag to do this:

xcodebuild -scheme <SchemeName> archive 

After this command the Archive will show up in the Xcode Organizer.

like image 33
Reid Ellis Avatar answered Oct 21 '22 09:10

Reid Ellis