1

I'm trying to build several targets and I already have Build Settings per target in Xcode. I also have a scheme per target. What I'm trying to do is issue one command line instruction to build each target, something like:

xcodebuild -project MyProject.xcodeproj -scheme PRODScheme archive -archivePath /Users/myUser/Documents/PRODApps/archives/"${PRODUCT_NAME}".xcarchive -configuration Release

Here, ${PRODUCT_NAME} is the Build Setting variable defined by XCode. I'm thinking on how xcodebuild can make use of the bunch of already defined settings.

Is there a way of reusing those settings in xcodebuild?

carlos_ms
  • 838
  • 9
  • 15
  • As a side note, the quotes in the **archive path** are incorrect. The proper line would be: -archivePath "/Users/myUser/Documents/PRODApps/archives/${PRODUCT_NAME}.xcarchive" You would place the quotes around the whole path. – Black Frog Jan 05 '15 at 17:56
  • possible duplicate of [Xcode "Build and Archive" from command line](http://stackoverflow.com/questions/2664885/xcode-build-and-archive-from-command-line) – Black Frog Jan 05 '15 at 17:56
  • @BlackFrog - I already tried what's Vincent has in his blog. Running the suggested command: xcodebuild -target "${PROJECT_NAME}" -sdk "${TARGET_SDK}" -configuration Release I get **xcodebuild: error: The project 'MyProject.xcodeproj' does not contain a target named ''.** because ${PROJECT_NAME} gets not value from the Build Settings... my whole point in my question above. BTW, changing quotes as suggested, didn't do much difference, no error, no gain either. In both cases the result is the same: empty/null values for the ${FOO} settings. – carlos_ms Jan 05 '15 at 20:23
  • Try removing the `{` `}`, i.e. `"$PROJECT_NAME"` – l'L'l Jan 05 '15 at 20:58
  • been there, done that... doesn't bring the build setting value either. – carlos_ms Jan 05 '15 at 21:00
  • So what you're basically after is a loop for `$PRODUCT_NAME` contained within `-archivePath`? – l'L'l Jan 05 '15 at 21:04
  • I'm looking to have 2 command-lines per schema: 1) build+archive in a custom path with a customized name I have defined in xcode and stored in PRODUCT_NAME setting, and 2) generate ipa file from the archive created in step 1. – carlos_ms Jan 05 '15 at 21:37

1 Answers1

2

Typically you would use the scheme, which would contain the other information you are trying to include:

xcodebuild -scheme PRODScheme build

To use with a configuration file you would use:

xcodebuild -target MyProject.xcodeproj -xcconfig configuration.xcconfig

To build all targets use -alltargets


Command Line tech notes: https://developer.apple.com/library/ios/technotes/tn2339/_index.html

Man xcodebuild: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • I tried before your suggested solution but it won't do what I'm looking for either. That puts the archive in the path set in Xcode and uses the **TARGET_NAME**. If you see my question, you'll see that what I'm trying to do is to use **PRODUCT_NAME** build setting's value -from Xcode- and use that as the path to my xcarchive file. If this is possible, then my next command-line would be **xcodebuild -exportArchive -exportFormat ipa -archivePath "/Users/myUser/Documents/PRODApps/archives/${PRODUCT_NAME}.xcarchive" -exportPath "/Users/myUser/Documents/PRODApps/ipas/${PRODUCT_NAME}.ipa"** – carlos_ms Jan 05 '15 at 20:57