19

Whats the best approach for generating an IPA file from command-line?

I'm on xcode 4.2 and generating the archive using:

xcodebuild -scheme AppStore clean archive

This generates the .dSYM and .app files in the build output directory, after codesigning. How should I proceed to generate the .ipa file? In other words, I'm looking for the command-line equivalent of doing the following in GUI

  1. Organizer - Archives
  2. Share
  3. iOS App Store Package
  4. Don't Re-sign

Thanks!

Vasanth
  • 193
  • 1
  • 1
  • 5

3 Answers3

19

The missing piece is using the PackageApplication utility.

/usr/bin/xcrun -sdk iphoneos PackageApplication -v $FULL_PATH_TO_APP -o $OUTPUT_PATH

You can also pass this script options for resigning, and profile embedding. Using the --sign and --embed flags respectively.

Joshua Weinberg
  • 28,598
  • 2
  • 97
  • 90
  • 1
    How can I access $FULL_PATH_TO_APP? If I'm building the app, instead of archiving, I could use BUILT_PRODUCTS_DIR. Whats the equivalent of BUILT_PRODUCTS_DIR for Archive product dir? I know I could change the location of archive dir to a custom location, but I would hate to have that dependency. Thanks for the answer! – Vasanth Dec 01 '11 at 22:14
  • BUILT_PRODUCTS_DIR should work for archive as well, but I thought you said you weren't archiving, but doing a normal build? – Joshua Weinberg Dec 01 '11 at 22:18
  • 1
    No, I'm archiving, but the .app files aren't in BUILT_PRODUCTS_DIR, which is `/Users/vasanth/Library/Developer/Xcode/DerivedData/Foo-drauzdtlrihjsddujotyhbjojcpa/Build/Products/Debug-iphoneos/Foo.app` rather its available here: `/Users/vasanth/Library/Developer/Xcode/DerivedData/Foo-drauzdtlrihjsddujotyhbjojcpa/ArchiveIntermediates/Debug/InstallationBuildProductsLocation/Applications/Foo.app`. But I just realized that I could use $INSTALL_DIR instead of $BUILT_PRODUCTS_DIR. – Vasanth Dec 01 '11 at 22:52
  • I like that answer more http://stackoverflow.com/questions/5640776/xcode4-alternative-way-to-build-ipas – bitle Mar 23 '13 at 22:57
  • This is no longer a valid answer PackageApplication does not exist – Cameron Lowell Palmer Apr 29 '20 at 10:46
8

This tool makes it trivial to build (and distribute): https://github.com/nomad/shenzhen

Rayfleck
  • 12,116
  • 8
  • 48
  • 74
7

After Archive, you need to "Export" to desired format ie ipa:

xcodebuild -sdk iphoneos7.0 -archivePath "path to archive file" -exportPath "path_for_export" -exportFormat ipa -exportArchive -exportProvisioningProfile "provisioning_profile_to_export_with"

srikanth Nutigattu
  • 1,077
  • 9
  • 15