Archive multiple IOS xcode target in command line - xcode

I have an iOS Xcode project that has several targets. The number of targets in the project will continue to grow as the project progresses and expands. When I create a new version, it is a pain to have to go through each target and manually create the Archive. I looked into how to archive multiple targets using the command line, but none of the answers spoke to what I was trying to accomplish. Any help and guidance is appreciated.
I believe that the following partial command is part of the solution:
xcodebuild archive
archive: Archive a scheme from the build root (SYMROOT). This requires specifying a workspace and scheme.

I suppose you want to build it for CI server Manually
If you want to read all the schemes in a xcode project
xcodebuild -list | awk 'p && NF {print \$0";";} /Schemes:/ {p=1}' > schemeList.txt
This will put all your schemes in a text file. Then you have to read the text file manually to retrieve each scheme.
You can use the below command line to produce the archive
xcodebuild -scheme ${schemeName} -sdk iphoneos$sdkVersion -configuration Release clean archive -archivePath ${archivePath}.xcarchive
And then the below xcode command to produce the ipa.
xcodebuild -exportArchive -archivePath ${archivePath}.xcarchive -exportOptionsPlist exportOptions.plist -exportPath ${exportPath}

Related

How to: `xcodebuild -xcworkspace..` with project and swift packages

I have created a xcworkspace to add my iOS.xcproj and local swift package. The workspace builds and runs great from Xcode. What would be the xcodebuild command to do in my CI?
I have been trying using the following:
xcodebuild -workspace [name].xcworkspace -scheme [scheme_name] -configuration [config] -xcconfig [path_xcconfig]
I get this in the output console:
...note: Building targets in dependency order
error: Multiple commands produce <RegisterExecutionPolicyException...
sample:
note: Target 'Firebase_FirebaseInAppMessaging_iOS' (project 'Firebase'): Touch /Users...

Xcode: Is it possible to build in command line exactly as in GUI?

I have an Xcode project that I myself did not author. It has a multi-stage build sequence that is not trivial. For the purposes of static-analysis I am attempting to build it from command line using xcode build. However, the command line invocation produces errors in the build that the GUI build does not.
Is there a sure-fire way to get an Xcode project to build exactly as it did in the command line as in the GUI?
I would be wonderful is there was a way to export an XCODEBUILD invocation from the GUI that covered all the build phases. Is this possible?
I am using an invocation like:
xcodebuild -workspace "PROJECT.xcworkspace" -scheme "MY SCHEME NAME" -sdk iphonesimulator8.1 -configuration Debug

the ipa created by command-line is smaller than create by xcode6,why?

The command-line script:
xcodebuild
xcodebuild -verbose ARCHS="armv7 arm64" VALID_ARCHS="armv7 armv7s arm64" ONLY_ACTIVE_ARCH=NO DEPLOYMENT_POSTPROCESSING=YES \
-configuration Release PROVISIONING_PROFILE="${profilename}" CODE_SIGN_IDENTITY="${codesign}" \
clean build OBJROOT=${distDir}/Obj.root SYMROOT=${distDir}/Sym.root
# ipa
appname=$(basename ${distDir}/Sym.root/Release-iphoneos/*.app*)
target_name=$(echo $appname | awk -F. '{print $1}')
mkdir -p $project_path/package/Products
xcrun -sdk iphoneos PackageApplication -v "${distDir}/Sym.root/Release-iphoneos/${target_name}.app" -o "$project_path/package/Products/${ipaName}" --embed "${profile}"
And the result is: command-line's ipa is 8M smaller than xcode one, Why?
Sadly, ipa files generated from the command line are not identical to those from the Xcode app.
As you already noted, the command line one has a few missing items.
In addition to Symbols, if your app is written in Swift, there will be a SwiftSupport folder with a few libraries in the ipa generated by the Xcode app but not the command line one. Similarly, if your app includes a Watch App, there will be a missing WatchKitSupport folder.
Some of these missing items will be problematic when it comes to uploading an ipa to iTunes Connect. You will find numerous posts about these issues and the workarounds being adopted - but it all boils down to this issue of command line builds lacking all the required content for app distribution.
Luckily, the new version of xcodebuild within Xcode 7 has a solution to most of these issues but is not yet documented. Here's some details on it if you are interested.

Xcode Project runner in TeamCity

What does the install ,installsrc and testdo while using the Xcode Project runner.
When I build using clean build archive I am getting only the .app and not .ipa .Are there any command line parameters that is to be added to the step.Please help me out.
The archive build action generates a .xcarchive file. To create an .ipa file you have to add a subsequent command line build step in teamcity with the following command:
xcodebuild -exportArchive -archivePath projectname.xcarchive -exportPath projectname -exportFormat ipa

xcodebuild arguments ignored when using archive

My name is Luca and I am currently working on iOS continuous integration to build apps in xcode for distribution (Ad Hoc and App Store) using shell-scripting.
So far I achieved good results with IPA files. My problem comes for distribution in App Store. To build a .app from script (passing some arguments) I do:
xcodebuild -scheme myScheme -configuration myConfiguration PRODUCT_NAME=myProductName TARGETED_DEVICE_FAMILY=myTargetedDeviceFamily .... etc
Since with XCode 4.2, apps submission is done using the XCode Organizer Window I must be able also to archive my executable.
Therefore I modify the previous command line as follow:
xcodebuild -scheme myScheme -configuration myConfiguration PRODUCT_NAME=myProductName TARGETED_DEVICE_FAMILY=myTargetedDeviceFamily .... etc **archive**
Unfortunately after I do so, it seems that the 'archive' argument force xcodebuild to ignore the other ones (PRODUCT_NAME, TARGETED_DEVICE_FAMILY, ....) and my output is built using the XCode predefined build settings.
I want to be able to pass the arguments with xcodebuild and be effective, but the 'archive' action seems to prevent this.
I am going nuts, please help :)
Thanks
The archive action for xcodebuild seems to have a bug in Xcode 4.2. Normally overrides for the project configuration can be specified as either command-line parameters or via the -xcconfig parameter.
Although the build action honors them, archive does not. (Presumably this is because archive is a meta-action that invokes build internally, but doesn't pass-through the options to the internal invocation.) There is an OpenRadar bug that describes this issue, so presumably it's been reported to Apple.
Finally, note that if you're going to use the archive action from a script then you can't rely on the exit code from xcodebuild. The archive action always yields an exit code of 0 (success, by convention). To detect build failure you need to scrape the output.
I've ran into this same issue. My current work-around is basically to delete the other configurations so archive is forced to use the one you want. Not really a solution that can be done via command-line, hopefully Apple will fix this glaring issue.
this may be too late for the original poster, but may help others. for my build process, i use xcodebuild to with first clean and then build, then i use xcrun to create the archive:
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "build/<Path_to_build_dir>/<App_Name>.app" -o "<Path_to_archive_output>.ipa" --sign "<signing identity>" --embed "<path to provision profile>.mobileprovision"
with this command, i can create an archive for the app store, or even upload an ad-hoc build to TestFlight like this:
curl http://testflightapp.com/api/builds.json \
-F file="<path to archive>" \
-F api_token='<api token>' \
-F team_token='<team token>' \
-F notes='Automated build' \
-F notify=True \
-F distribution_lists='me'
this works as of xcode 6.1

Resources