xcodebuild Archive [duplicate] - iphone
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:
/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.
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.
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.
Use the full path to xcodebuild,
/Applications/Xcode 9.3.1.app/Contents/Developer/usr/bin/xcodebuild
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.
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.
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).
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>Ä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.
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"
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"
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.
I have given a brief description of steps to follow, and parameters to pass while generating an ipa using terrminal below:
Go to the folder which contains the MyApp.xcodeproject file in terminal
By using the command given below you will get all the Targets of the application
/usr/bin/xcodebuild -list
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
The above command builds the project and creates a .app file.The path to locate the .app file is ./build/Release-iphoneos/MyApp.app
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”)
ipa will be generated at selected output directory "${OUTDIR}"
Go to the folder where's your project root and:
xcodebuild -project projectname -activetarget -activeconfiguration archive
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
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
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
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.
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:
Runs the same tests as Xcode.app.
Structured output of build and test results.
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
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
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.
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
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.
Related
xcodebuild fails to create Archive due to SymLink error with Alamofire
This is really winding me up now, all I am trying to do is an Xcode CLI build using the Xcode command line tools. The flow is as follows: App Code is cloned from Git Info Plist and my own custom plist are generated and copied to project folder A new app icon set copied over into the assets directory Xcode Archive build is executed Xcode generate IPA build is executed The issue is the Archive part keeps failing, and I cannot get it working. Annoyingly it works fine if I open the project in Xcode and Archive it through there, but that defeats the point of this automated process. This is the command xcodebuild -verbose -scheme EpicHRV1.1.0 -archivePath ios/app.xcarchive archive And here is the constant resultant error. I really can't figure out what its complaining about, I mean, it says something to do with Alamofire and missing modules, but why would this work in Xcode but not the command line? Command failed: xcodebuild -verbose -scheme EpicHRV1.1.0 -archivePath ios/app.xcarchive archive 2017-01-07 20:24:04.255 xcodebuild[43780:2460638] DVTAssertions: Warning in /Library/Caches/com.apple.xbs/Sources/DVTFrameworks/DVTFrameworks-11754/DVTFoundation/Utilities/DVTFileSystemUtilities.mm:142 Details: lstat('/Users/Justin/Library/Developer/Xcode/DerivedData/EpicHR-dgdtmzwowkyxgkfzmizhuhiaxkrt/Build/Intermediates/ArchiveIntermediates/EpicHRV1.1.0/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Alamofire.framework/Modules') failed with errno 2 (No such file or directory) Function: DVTRecursiveMkdirResult dvt_recursiveMkdir_returningErrorString(NSString *__strong, NSString *__autoreleasing *) Thread: <NSThread: 0x7f90e8ae7cf0>{number = 7, name = (null)} Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide. ** ARCHIVE FAILED ** Here is another lovely error which also randomly appears, but not every time... The following build commands failed: SymLink /Users/Justin/Library/Developer/Xcode/DerivedData/EpicHR-dgdtmzwowkyxgkfzmizhuhiaxkrt/Build/Intermediates/ArchiveIntermediates/EpicHRV1.1.0/BuildProductsPath/Release-iphoneos/Alamofire.framework /Users/Justin/Library/Developer/Xcode/DerivedData/EpicHR-dgdtmzwowkyxgkfzmizhuhiaxkrt/Build/Intermediates/ArchiveIntermediates/EpicHRV1.1.0/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Alamofire.framework And another error that sometimes appears. With all of the above the only consistent thing is Alamofire is mentioned in the error.. The following build commands failed: Strip /Users/Justin/Library/Developer/Xcode/DerivedData/EpicHR-dgdtmzwowkyxgkfzmizhuhiaxkrt/Build/Intermediates/ArchiveIntermediates/EpicHRV1.1.0/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Alamofire.framework/Alamofire
So I solved it with the following commands: xcodebuild -scheme EpicHRV1.1.0 -archivePath ../ios/app.xcarchive archive xcrun xcodebuild -exportArchive -exportOptionsPlist exportPlist.plist -archivePath ../ios/app.xcarchive -exportPath ../ios/ipa/
no product after "build success" of a cocoa touch static library project
I have searched so many problem but there is no the same as me. on Xcode 4.3.2(4.3.1) I added several files to a new cocoa touch static library project and use iPhone Simulator to build it, then receive build success, but no .a file in products group (the .a file is red in the files list, left of Xcode) When I change the "iPhone Simulator" to IOS Device, also receive build success, but now I can see .a file is not red and I can find in the product folder^ After I use lipo -info to check the .a file, it shows that it only supports arm7 architecture, thus confirms my first action(no product built in Simulator)^ so the .a file can't be used in my another project(i know it only can be used in simulator by supporting i386 architecture)
Use the command line. Here is a simple script I built a while back, it will even lipo your binaries together for you! #!/bin/bash #build the device echo building for ARM architecture xcodebuild -sdk iphoneos4.3 "ARCHS=armv6 armv7" build > /dev/null #build the simulator echo building for the i386 architecture xcodebuild -sdk iphonesimulator4.3 "ARCHS=i386 x86_64" "VALID_ARCHS=i386 x86_64" build > /dev/null #make the folder mkdir "Fat Binary" #lipo suck it together echo lipo binaries together lipo -output Fat\ Binary/libMyLib.a -create build/Release-iphoneos/liblibMyLib.a build/Release-iphonesimulator/libMyLib.a echo lipo binary saved at $./Fat Binary/libMyLib.a echo coping headers cp -R build/Release-iphoneos/usr "Fat Binary" echo [COMPLETE] Just replace occurrences of libMyLib.a with the name of your library.
(iphone) build xcode4 project from command line
I've used to build my project with xcodebuild -proj MyProject.xcodeproj -target MyTarget - configuration Debug -sdk iphonesimulator4.3 this works(it builds fine) but when I hit run in xcode, it recompiles. (with xcode3, there was no need to rebuild once I build using command line) I suspect xcode build use workspace/scheme rather than project/target. How do I find out the workspace name that my current xcode project is using? Thank you edit Chetan's links gave me directions what to look for. xcode4 stores build output in ~/Library/... whereas xcodebuild -project .. saves build output in project's build directory. (if you want the workspace capability, you can't use the build directory for build output) I created a workspace containing my project and ran xcodebuild -workspace myWorkSpace -scheme myScheme this saves build output in ~/Library/...../Debug-iphoneos whereas xcode4 run button from the same workspace and same scheme saves output in ~/Library/..../Debug-iphonesimulator any guess on why xcodebuild command uses Debug-iphoneos? :( edit2 xcodebuild -workspace myWorkSpace -scheme myScheme -sdk iphonesimulator4.3 specifying sdk solved it
I know it isn't strictly the answer to your question, but you can configure the output directory of your build using the CONFIGURATION_BUILD_DIR environment variable. Source: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/0-Introduction/introduction.html#//apple_ref/doc/uid/TP40003931-CH1-SW1
To automate xcode 'Build and Archive' [duplicate]
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: /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.
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.
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. Use the full path to xcodebuild, /Applications/Xcode 9.3.1.app/Contents/Developer/usr/bin/xcodebuild 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.
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.
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).
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>Ä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.
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"
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"
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.
I have given a brief description of steps to follow, and parameters to pass while generating an ipa using terrminal below: Go to the folder which contains the MyApp.xcodeproject file in terminal By using the command given below you will get all the Targets of the application /usr/bin/xcodebuild -list 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 The above command builds the project and creates a .app file.The path to locate the .app file is ./build/Release-iphoneos/MyApp.app 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”) ipa will be generated at selected output directory "${OUTDIR}"
Go to the folder where's your project root and: xcodebuild -project projectname -activetarget -activeconfiguration archive
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
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
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
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.
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: Runs the same tests as Xcode.app. Structured output of build and test results. 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
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
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.
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
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.
Automating Xcode development
Can everything which is done through Xcode GUI be done through command line, like changing app name, changing provisional profile, distribution profile? If yes then how. May be it can be done through xcodebuild , but till now i am only able to compile through xcodebuild.
Yes. Building can be done through xcodebuild: $ xcodebuild -help Usage: xcodebuild [-project <projectname>] [-activetarget] [-alltargets] [-target <targetname>]... [-parallelizeTargets] [-activeconfiguration] [-configuration <configurationname>] [-sdk <sdkfullpath>|<sdkname>] [-xcconfig <filepath>] [<buildsetting>=<value>]... [<buildaction>]... xcodebuild [-version [-sdk [<sdkfullpath>|<sdkname>] [<item>] ] xcodebuild [-showsdks] xcodebuild [-find <binary> -sdk <sdkfullpath>|<sdkname>] xcodebuild [-list] …but I see you already know that. The application name can be changed by simply editing the Info.plist file. And I think you can change the profiles by hacking the *.pbxproj file (it’s a regular text file). You can save a copy of the project file, change a profile through the IDE and then diff the new version and the saved copy to see the changes: $ find . -name '*.pbxproj' ./Source/Foo.xcodeproj/project.pbxproj $ cp Source/Foo.xcodeproj/project.pbxproj ~/Desktop # …now changing the profile through IDE… $ diff Source/Foo.xcodeproj/project.pbxproj ~/Desktop/project.pbxproj 517d516 < "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "…"; 534d532 < "PROVISIONING_PROFILE[sdk=iphoneos*]" = "…"; But it depends on what you are trying to do. You could switch the profiles much easier by setting different profiles for different build modes (Debug/Distribution/Whatever).