12

Question - short version:

Why won't my build phase scripts be executed when creating an IPA from the command line? When I'm running xcodebuild to create an IPA the predefined build phase scripts does not get executed. Why is that?


Question - lengthy version:

I have a workspace with a scheme I want to create an IPA out of from command line.

This works fine except for one thing; I have two scripts in the build phases of the target that is used to put the correct app version (CFBundleShortVersionString) and the correct svn revision number (CFBundleVersion). These to scripts works fine when archiving from xcode but for some reason they do not get run when archiving from command line. First of all why is that?

Here are the scripts that are working (if archiving form xCode) enter image description here enter image description here

When archiving and creating the IPA from the command line I do (the essentials)

# Building
xcodebuild ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release clean build

# Creating IPA
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PROJECT_BUILD_DIR}/${APPLICATION_NAME}.app" -o "${IPA_OUTPUT_PATH}/${APPLICATION_NAME}.ipa"

It works and creates an IPA but none of the build phase scripts gets executed leaving both the revision number and version number untouched.

All suggestions are appreciated!

UPDATE DUE TO BDASH's ANSWER

Instead of making a clean build I make an install as

xcodebuild install ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release

The predefined script will IN FACT be executed (can be seen in the project version number) with no errors during the install. However the created IPA will have a size of ~300 bytes (instead of ~10MB) and cannot be installed on a device.

Building the app before installing it, i.e.

# Building
xcodebuild clean build ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release 
# Installing
xcodebuild install ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release

and then creating the IPA will result in an IPA with executed version script and of correct size BUT it is not possible installing it on a device. Trying to put it on a device will give an error message saying
"The program "MyApp" was not installed on you iPhone device "My Device" because an unknown error has occurred."

Groot
  • 13,943
  • 6
  • 61
  • 72

1 Answers1

3

You have "Run script only when installing" checked for at least one of the script phases. That phase won't be run when using the build action to xcodebuild, only if using the install action.

bdash
  • 18,110
  • 1
  • 59
  • 91
  • Updated my question from the result of your answer. – Groot Apr 24 '13 at 08:16
  • When you use the `install` action, the built product is installed to the directory specified by the `DSTROOT` configuration setting. That defaults to `/tmp/ProjectName.dst` unless you override it on the `xcodebuild` command line. This doesn't have much to do with your question as initially asked though. – bdash Apr 24 '13 at 08:22
  • Thanks for your helps bdash! I am overriding the directory from command line having both the 'build' and the 'install' put to the same directory. You are correct that this deviates a bit from the original question but the fact remains that the first om my scripts doesn't get executed. – Groot Apr 24 '13 at 08:35
  • To clarify, are you saying that with my suggestion only the second script is executed (the one with "Run script only when installing" checked), while in your initial attempt neither was executed? How are you confirming that the scripts were not executed? Is it possible that they were executed but simply not giving you the result you'd expect? – bdash Apr 24 '13 at 08:54
  • The scripts both work if archiving directly from xCode. If I can install the app on a device I confirm this by the version number visible in the app, otherwise I *"confirm"* this by dropping the IPA into TestFlight that reads back both the version and revision number. In my initial attempt none of the scripts were executed but an installable IPA was created and with your suggestion the second script was executed but resulted in an invalid IPA for some reason. – Groot Apr 24 '13 at 09:04
  • Two things: First, note that the `xcodebuild install` command line you added doesn't appear to set `DSTROOT` as I noted above. When `install` is used the built product is written to `DSTROOT` rather than the regular build directory. Secondly, looking at the `xcodebuild` output is a much more reliable way to determine whether the script phase is run. You'll see a command header mentioning `PhaseScriptExecution` followed by the name of the script phase when it is executed. – bdash Apr 24 '13 at 09:14
  • Thanks, the version number is now updated correctly and both scripts are executed (I can see them in the command line). However the revision number (CFBundleVersion) is for some reason set to *nothing at all* when the first of my scripts is executed. This script works when archiving from xCode but I suppose that is a different question. Thanks anyway, the bounty is yours! (If you could give any hint why the revision number is not updated I would however be most happy :) ) – Groot Apr 24 '13 at 10:11