Xcode "Build and Archive" from command line
Asked Answered
B

20

451

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.

Beauharnais answered 19/4, 2010 at 2:18 Comment(7)
Aw, crud. This appears to be impossible. If you don't know the answer, please at least vote up the question so my bounty doesn't vanish into the ether... :-(Beauharnais
This isn't impossible, it just isn't part of xcodebuild. Creating an IPA file just involves putting the app into a directory named "Payload", zipping that directory, and renaming it to MyAppName.ipa.Infirmity
@Michael, "Build and Archive" also enables the Organizer features, which are not available when you just make an IPA file by hand.Beauharnais
My comment got a bit long, so it's posted as an answer.Infirmity
Although the first/accepted answer by vdaubry will work, the answer by Reid is much simpler for the newer versions of Xcode.Isomorph
I just added an answer for uploading to itunesConnect, which works for me as part of a Cordova based build-script; I don't touch Xcode at all! I can log into itunesConnect and select it for beta testing.Autolysis
I strongly recommend you to use tools like Fastlane for export IPA.Ineludible
E
329

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.

Eldrid answered 16/11, 2010 at 19:31 Comment(17)
Not obvious to me for some time, but RELEASE_BUILDDIR needs to be an absolute path.Famish
Also note that you don't need the --sign or --embed options if you wish to keep the same signing/profile used when the .app was built. This will be whatever you have set up in the Code Signing build settings for your Release configuration.Bedabble
Using a Run Script phase in an enveloping Aggregate Target, you can even automate this command and subsequent uploading/emailing/... of the ipa file. (without the Aggregate Target, the script will run too early)Cantor
It works good on MacOs 10.6. What about 10.7? I have problem with new OSX. A lot :)Spacesuit
Note that the ipa file path in -o "${ipa_path}" must be an absolute path. Otherwise you will probably get error: Unable to create '.../...ipa' or it will be silently ignored creating. Damn it wasted me a couple of hours.Sophey
Can someone tell me what the {} braces do? I'm assuming they take care of blankspace, but I could be wrong.Fop
the braces are just a more explicit way to delimit the variable name from the surrounding stringBedabble
I'm having an issue with xcrun and single quotes. Basically, xcrun bombs when the --sign argument has a single quote in the name. See here: #16597114 has any of come across an issue like this?Skippie
The .app path can't end in a /Mauser
{RELEASE_BUILDDIR}, {APPLICATION_NAME}.app", {BUILD_HISTORY_DIR} {APPLICATION_NAME}.ipa", {DEVELOPER_NAME}", {PROVISONING_PROFILE}". Can u Please Explain the above parameters specified by you inside the paranthesis because i think i'm missing something in the command written by you,and below is`the error that i'm getting: error: Specified application doesn't exist or isn't a bundle directory : 'Birch.app'Repp
Your error means the path you provide to the .app file either doesn't exist or your file isn't a valid compiled applicationEldrid
I tried it in terminal, it is not doing anything, it just entera new line with nothing...and my output directory remains empty. I was trying this becuase by xoce never finishes Archiving , it just stops at the end.Tercentenary
If you don't want to enter an absolute path, and you use bash, you can simply expand the path with $(pwd), e.g.: /usr/bin/xcrun -sdk iphoneos PackageApplication -v "your.app" -o "$(pwd)/your.ipa" --sign "$DEVELOPER" --embed "profile.mobileprovision"Gailgaile
Thank you for writing this, can you update this to work with xcode 8 ? ThanksCursive
This answer is outdated.Nomothetic
Xcode 8.3 Beta 1 remove the PackageApplication command completely. Do not use it again and use "xcodebuild -scheme <SchemeName> archive" as suggested below.Ganymede
Is this possible for macos apps as well?Pantsuit
F
296

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.

Farceur answered 26/10, 2011 at 20:19 Comment(10)
Yes, much better! In order to make it work, I did the following : cd to your project folder, then run "xcodebuild -scheme MyProjectName archive" (because usually, you have a scheme with the same name as your project name)Photopia
Note that the archive action does not honor any settings you provide through this invocation, apart from the workspace and scheme — this has just cost me hours!Pathway
"the archive action does not honor any settings you provide through this invocation" - please submit bug reports on this if it affects you! This needs to get fixed.Bedabble
Current (Xcode 4.3) gives unsupported build action 'archive' when trying to use this command.Hangdog
Works fine in Xcode 4.4, and I'm sure it was fine in 4.3 as well. Make sure you have selected the correct Xcode release by using xcode-select <path to Xcode.app>Farceur
Also, you must specify the scheme with "-scheme <SchemeName>"Farceur
This is fine for creating the archive, however the PackageApplication in xcrun actually creates the .ipa file. You need this file for distribution to beta testers via something like TestFlightPoirer
I am trying to integrate this process with a continuous integration tool so I can distribute to testers. Where on the filesystem does the .ipa get placed?Aruspex
You don't need an ipa to distribute over testflight. Archive is fine.Fosterling
Archive succeed but no ipa in organizer or anywhere. I searched in spotlightTercentenary
F
193

Updating my answer with Xcode 9 and Swift

Archive

xcodebuild -workspace <ProjectName>/<ProjectName>.xcworkspace \
  -scheme <schemeName> clean archive -configuration release \
  -sdk iphoneos -archivePath <ProjectName>.xcarchive

IPA Export (please note the export options plist)

xcodebuild -exportArchive -archivePath  <ProjectName>.xcarchive \
  -exportOptionsPlist  <ProjectName>/exportOptions.plist \
  -exportPath  <ProjectName>.ipa

For those who don't know about exportOptions.plist, https://blog.bitrise.io/post/new-export-options-plist-in-xcode-9


Those who were using this for building project in CI/CD tools like teamcity/jenkins, please make sure you are using the right Xcode installed in the build agent for both archive and export.

You can use either of below 2 options for this.

  1. Use the full path to xcodebuild,
/Applications/Xcode 9.3.1.app/Contents/Developer/usr/bin/xcodebuild
  1. Use xcode-select,
xcode-select -switch /Applications/Xcode 9.3.1.app

Below is my old answer

Here is command line script for creating archive and IPA example. I have an iPhone xcode project , which is located in Desktop/MyiOSApp folder.

Execute following commands one by one:

cd /Users/username/Desktop/MyiOSApp/

xcodebuild -scheme MyiOSApp archive \
  -archivePath /Users/username/Desktop/MyiOSApp.xcarchive

xcodebuild -exportArchive -exportFormat ipa \
  -archivePath "/Users/username/Desktop/MyiOSApp.xcarchive" \
  -exportPath "/Users/username/Desktop/MyiOSApp.ipa" \
  -exportProvisioningProfile "MyCompany Distribution Profile"

This is tested with Xcode 5 and working fine for me.

Fledgling answered 8/11, 2013 at 9:51 Comment(7)
It worked perfectly on Xcode6.1.1 . I choose to build my apps from terminal because Xcode6 gives me an "Your account already has a valid certificate" error when I try to build an AdHoc distribution from organizer.Plague
If you have a WatchKit app then there is a new folder in the ipa called WatchKitSupport as well as a Symbols folder (may be optional). Do you know if there is a way to get the exportArcive to export these too?Pentothal
xcodebuild -workspace <ProjectName>/<ProjectName>.xcworkspace -scheme <schemeName> clean archive -configuration release -sdk iphoneos -archivePath <ProjectName>.xcarchive is throwing error : requires a provisioning profile with the Associated Domains feature. Select a provisioning profile for the "Release" build configuration in the project editor.Reheat
exportProvisioningProfile is not a valid option anymoreMonadnock
@MohammadRezaKoohkan that was in the old answer I kept it for showing the reference, you can see the valid export option at the beginning of my answerFledgling
Just wanted to add that you should close the XCode project if you test these commands locally. Mine crashed (so i guess the problem fixed it self)Flourishing
to build a full exportOptionsPlist, walk through the archive and export steps manually in xcode once. The ExportOptions.plist file can be reused with your automated processButene
S
32

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.

Swoon answered 1/5, 2010 at 9:15 Comment(6)
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?Infirmity
Where does xcode gets the "APPNAME.ipa" name? From Packaging-> Product Name ?Tabbatha
This script is not enough now with the WatchKit app. Does anyone know the new specifications of the ipa file with the watchkit app?Pentothal
Seeing same issues as @Pentothal with watch kit. Any resolution?Petrarch
@Pentothal check this out for the WatchKit stuff. I haven't tried it myself, but seems pretty thorough matrixprojects.net/p/watchkit-command-line-buildsEdward
@Petrarch check this out for the WatchKit stuff. I haven't tried it myself, but seems pretty thorough matrixprojects.net/p/watchkit-command-line-buildsEdward
F
26

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:

xcodebuild -scheme <scheme name> archive

Given $ARCHIVE_PATH (the path to the .xcarchive file), export the app from the archive with one of the following:

iOS .ipa file:

xcodebuild -exportArchive -exportFormat ipa -archivePath "$ARCHIVE_PATH" -exportPath "myApp.ipa" -exportProvisioningProfile "My App Provisioning profile"

Mac .app file:

xcodebuild -exportArchive -exportFormat app -archivePath "$ARCHIVE_PATH" -exportPath "myApp.app" -exportSigningIdentity "Developer ID Application: My Software Company"

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

Foretooth answered 31/10, 2013 at 1:43 Comment(3)
Doesn't work when using xcode workspaces and not compatible with cocopodsSpectrograph
Have you tried adding the -workspace option to xcodebuild (and a path to a workspace)? man xcodebuild states: "To build an Xcode workspace, you must pass both the -workspace and -scheme options to define the build".Foretooth
This works great for me with the -workspace option added--I just needed to get the path of the archive created by the first command, so I could feed it into the second. You can specify where the archive is created with the -archivePath option, but I prefer its default location. This helped me figure out how to get that path: https://mcmap.net/q/81550/-generate-xcarchive-into-a-specific-folder-from-the-command-lineMetalinguistic
E
25

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:

# Unlock keychain
security unlock-keychain -p jenkins /Users/jenkins/Library/Keychains/login.keychain

# Build and sign app
xcodebuild -configuration Distribution clean build

# Set variables
APP_PATH="$PWD/build/Distribution-iphoneos/iPadApp.app"
VERSION=`defaults read $APP_PATH/Info CFBundleShortVersionString`
REVISION=`defaults read $APP_PATH/Info CFBundleVersion`
DATE=`date +"%Y%m%d-%H%M%S"`
ITUNES_LINK="<a href=\"itms-services:\/\/?action=download-manifest\&url=https:\/\/xxx.xxx.xxx\/iPadApp-$VERSION.$REVISION-$DATE.plist\">Download iPad2-App v$VERSION.$REVISION-$DATE<\/a>"

# Package and verify app
xcrun -sdk iphoneos PackageApplication -v build/Distribution-iphoneos/iPadApp.app -o $PWD/iPadApp-$VERSION.$REVISION-$DATE.ipa

# Create plist
cat iPadApp.plist.template | sed -e "s/\${VERSION}/$VERSION/" -e "s/\${DATE}/$DATE/" -e "s/\${REVISION}/$REVISION/" > iPadApp-$VERSION.$REVISION-$DATE.plist

# Update index.html
curl https://xxx.xxx.xxx/index.html -o index.html.$DATE
cat index.html.$DATE | sed -n '1h;1!H;${;g;s/\(<h3>Aktuelle Version<\/h3>\)\(.*\)\(<h3>&Auml;ltere Versionen<\/h3>.<ul>.<li>\)/\1\
${ITUNES_LINK}\
\3\2<\/li>\
<li>/g;p;}' | sed -e "s/\${ITUNES_LINK}/$ITUNES_LINK/" > index.html

Then Jenkins uploads the ipa, plist and html files to our webserver.

This is the plist template:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>items</key>
    <array>
        <dict>
            <key>assets</key>
            <array>
                <dict>
                    <key>kind</key>
                    <string>software-package</string>
                    <key>url</key>
                    <string>https://xxx.xxx.xxx/iPadApp-${VERSION}.${REVISION}-${DATE}.ipa</string>
                </dict>
                <dict>
                    <key>kind</key>
                    <string>full-size-image</string>
                    <key>needs-shine</key>
                    <true/>
                    <key>url</key>
                    <string>https://xxx.xxx.xxx/iPadApp.png</string>
                </dict>
                <dict>
                    <key>kind</key>
                    <string>display-image</string>
                    <key>needs-shine</key>
                    <true/>
                    <key>url</key>
                    <string>https://xxx.xxx.xxx/iPadApp_sm.png</string>
                </dict>
            </array>
            <key>metadata</key>
            <dict>
                <key>bundle-identifier</key>
                <string>xxx.xxx.xxx.iPadApp</string>
                <key>bundle-version</key>
                <string>${VERSION}</string>
                <key>kind</key>
                <string>software</string>
                <key>subtitle</key>
                <string>iPad2-App</string>
                <key>title</key>
                <string>iPadApp</string>
            </dict>
        </dict>
    </array>
</dict>
</plist>

To set this up, you have to import the distribution certificate and provisioning profile into the designated user's keychain.

Electronic answered 11/6, 2012 at 14:1 Comment(3)
You can also change a plist-file with the Plistbuddy command of Apple, eg: /usr/libexec/PlistBuddy -c "Set :CFBundleVersion 1.2.3.4" /path/to/info.plist . In stead of playing with SED :)Customs
Thanks for the info. I'm more experienced with sed than plistbuddy, so I choose sed :)Electronic
I recommend $WORKSPACE instead of $PWD for generating APP_PATHSalutatory
R
16

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:

xcrun -sdk iphoneos PackageApplication \
    "/path/to/build/MyApp.app" \
    -o "output/path/to/MyApp.ipa" \
    --sign "iPhone Distribution: My Company" \
    --embed "/path/to/something.mobileprovision"
Rivkarivkah answered 28/6, 2011 at 18:42 Comment(0)
A
15

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:

codesign -f -vv -s "$DistributionIdentity" "$APPDIR"
Anabaptist answered 13/2, 2011 at 14:55 Comment(0)
G
14

I have given a brief description of steps to follow, and parameters to pass while generating an ipa using terrminal below:

  1. Go to the folder which contains the MyApp.xcodeproject file in terminal

  2. By using the command given below you will get all the Targets of the application

    /usr/bin/xcodebuild -list 
    
  3. After the above command is executed, you will get a list of targets of which you should select a specific target you need to generate .ipa

    /usr/bin/xcodebuild -target $TARGET -sdk iphoneos -configuration Release
    
  4. The above command builds the project and creates a .app file.The path to locate the .app file is ./build/Release-iphoneos/MyApp.app

  5. After Build gets succeeded then execute the following command to generate .ipa of the application using Developer Name and Provisioning Profile using the syntax below:

    /usr/bin/xcrun -sdk iphoneos PackageApplication -v “${TARGET}.app” -o “${OUTDIR}/${TARGET}.ipa” –sign “${IDENTITY}” –embed “${PROVISONING_PROFILE}”
    

Explanation of each Parameter in the above syntax:

${TARGET}.app                == Target path (ex :/Users/XXXXXX/desktop/Application/build/Release-iphoneos/MyApp.app)
${OUTDIR}                    == Select the output directory(Where you want to save .ipa file)
${IDENTITY}                   == iPhone Developer: XXXXXXX (XXXXXXXXXX)(which can be obtained from Keychain access)
${PROVISONING_PROFILE}   == Path to the provisioning profile(/Users/XXXXXX/Library/MobileDevice/Provisioning Profiles/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.mobileprovision”)
  1. ipa will be generated at selected output directory "${OUTDIR}"
Genitive answered 21/8, 2013 at 9:17 Comment(2)
I am seeing this error "specified application does not exist or isn't a bundle directory"Mehta
xcrun PackageApplication is deprecated.Johanajohanan
S
14

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.

cd MyProjectFolder

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),

xcrun xcodebuild -scheme MyApp -configuration Release archive -archivePath build/MyApp.xcarchive

Step 4, export as .ipa file like this, which differs from Xcode6

xcrun xcodebuild -exportArchive -exportPath build/ -archivePath build/MyApp.xcarchive/ -exportOptionsPlist exportOptions.plist

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.

Soviet answered 6/11, 2015 at 11:58 Comment(8)
how do you specify the provisioning profile with this approach. i tried the exportProvisioningProfile but it said that cannot be used with exportOptionsPlist... and there is no way to specify the profile in the plist that i can find... it seems to just take the oldest one with the same name as the one that built it (which is the opposite of what i want, really)Guarantor
Project settings, included in a file named "project.pbxproj", has signing settings, so -scheme and -configuration options specified how to sign the ipa file.Soviet
When you say "just send it to Apple", what is that process since this is outside the normal Archive steps?Autolysis
There are two ways to "send it to Apple", login to itunesconnect.apple.com, or using Xcode->Open Developer Tool->Application Loader. @AutolysisSoviet
So, no automated way, but uploading the result produced from the command line should work with both options. Thanks!Autolysis
I ended up finding a fully automated solution, for which I have created a new answer!Autolysis
The path of "Application Loader" will tell you the answer, I think.Soviet
-exportOptionsPlist exportOptions.plist Where can i get exportOptions.plist. I can able to clean,build and archive now. But when i generate .ipa i am getting this error "Couldn't load -exportOptionsPlist: The file “MyApp.plist” couldn’t be opened because there is no such file". Which path i have to add into -exportOptionsPlist?Craver
M
8

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

xcodebuild -project projectname -activetarget -activeconfiguration archive
Munafo answered 27/4, 2010 at 17:39 Comment(1)
This doesn't seem to work. The 'archive' buildaction isn't available in XCode 3.2.2 (final).Clevelandclevenger
C
8

Xcode 8:


IPA Format:

xcodebuild -exportArchive -exportFormat IPA -archivePath MyMobileApp.xcarchive -exportPath MyMobileApp.ipa -exportProvisioningProfile 'MyMobileApp Distribution Profile'

Exports the archive MyMobileApp.xcarchive as an IPA file to the path MyMobileApp.ipa using the provisioning profile MyMobileApp Distribution Profile.

APP Format:

xcodebuild -exportArchive -exportFormat APP -archivePath MyMacApp.xcarchive -exportPath MyMacApp.pkg -exportSigningIdentity 'Developer ID Application: My Team'

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

Cursive answered 5/10, 2016 at 17:4 Comment(1)
-exportFormat no longer supportedMarchall
N
8

How to build iOS project with command?

Clean : xcodebuild clean -workspace work-space-name.xcworkspace -scheme scheme-name 

&&

Archive : xcodebuild archive -workspace work-space-name.xcworkspace -scheme "scheme-name" -configuration Release -archivePath IPA-name.xcarchive 

&&

Export : xcodebuild -exportArchive -archivePath IPA-name.xcarchive -exportPath IPA-name.ipa -exportOptionsPlist exportOptions.plist

**What is ExportOptions.plist?**

ExportOptions.plist is required in Xcode . It lets you to specify some options when you create an ipa file. You can select the options in a friendly UI when you use Xcode to archive your app.

Important: Method for release and development is different in ExportOptions.plist

AppStore :

exportOptions_release ~ method = app-store

Development

exportOptions_dev ~ method = development

Nashua answered 13/2, 2019 at 4:45 Comment(1)
Still confused about the plist. Can I generate this somehow from xcode? Is there a sample I can use as a reference?Marchall
A
4

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.

/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool

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.

export PATH=$PATH:/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/

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:

ln -s /Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/itms /usr/local/itms
Autolysis answered 23/3, 2016 at 19:25 Comment(0)
G
3

Improving on Vincent's answer, I wrote a script to do that: xcodearchive
It allows you to archive (generate an ipa) your project via the command line. Think of it like the sister of the xcodebuild command, but for archiving.

Code is available on github: http://github.com/gcerquant/xcodearchive


One option of the script is to enable the archiving of the dSYM symbols in a timestamped archive. No excuse to not keep the symbols anymore, and not be able to symbolicate the crash log you might later receive.

Glisson answered 17/11, 2011 at 11:47 Comment(1)
@KunalBalani No, I would not expect it to handle workspace correctly. Have a look at the code, it would not take much work to adapt it. Pull requests welcome!Glisson
M
3

Open Terminal & drag and drop your project folder:

cd /Users/username/Desktop/demo/

Execute the following commands one by one:

Builds app as-"demo.xcodeproj" into an archive

xcodebuild archive -project demo.xcodeproj -scheme demo -archivePath /Users/username/Desktop/demo.xcarchive

If your app has Podfile fie as-"demo.xcworkspace"-

xcodebuild -workspace Project-Name.xcworkspace -scheme Scheme-Name -sdk iphoneos -configuration Release Provisioning_Profile=“Provision-Name” Development_Team=“Team-ID” archive -archivePath /Path/To/Output/AppName.xcarchive archive

IPA Export Build Command

Download ExportOptions.plist file from Here

xcodebuild -exportArchive -archivePath /Users/shilpa/Desktop/demo.xcarchive -exportPath /Users/shilpa/Desktop/demo.ipa -exportOptionsPlist /Users/shilpa/Downloads/ExportOptions.plist

Muscovado answered 18/9, 2020 at 7:22 Comment(0)
D
2

try xctool, it is a replacement for Apple's xcodebuild that makes it easier to build and test iOS and Mac products. It's especially helpful for continuous integration. It has a few extra features:

  1. Runs the same tests as Xcode.app.
  2. Structured output of build and test results.
  3. Human-friendly, ANSI-colored output.

No.3 is extremely useful. I don't if anyone can read the console output of xcodebuild, I can't, usually it gave me one line with 5000+ characters. Even harder to read than a thesis paper.

xctool: https://github.com/facebook/xctool

Despotism answered 16/5, 2013 at 21:43 Comment(0)
H
2

if you use next tool: https://github.com/nomad/shenzhen

then this task is very easy:

which ipa 1>/dev/null 2>&1 || echo 'no shenzhen. to install use: sudo gem install shenzhen --no-ri --no-rdoc'
ipa build --verbose --scheme "${schemeName}"

source

Honewort answered 14/1, 2015 at 19:3 Comment(0)
T
2

After updating to Xcode 8, I found that enterprise ipa generate by

/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}" 

Command cannot be launched because of some signature issue. The log indicates that "warning: PackageApplication is deprecated, use xcodebuild -exportArchive instead.

So I switch to xcodebuild -exportArchive and everything went back normal.

Thorley answered 23/9, 2016 at 3:55 Comment(0)
I
1

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.

Infirmity answered 20/7, 2010 at 19:17 Comment(3)
I clarified my question. When you say "I can" above, do you mean you can actually do this today?Beauharnais
Yes. I'm using Hudson Continuous Integration with a custom script which runs xcodebuild and makes an IPA.Infirmity
Sorry I'm late to the party, but TestFlight has a super easy upload API that you should check outMicrocircuit

© 2022 - 2024 — McMap. All rights reserved.