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

2
  • I would assume that if you are building from the commandline, xcodebuild assumes as well that you are executing the script yourself. Seems like a bug to me. Apr 20, 2013 at 14:58
  • Did you actually eventually get to a solution?
    – fatuhoku
    Sep 30, 2015 at 17:47

1 Answer 1

3
+50

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.

7
  • Updated my question from the result of your answer.
    – Groot
    Apr 24, 2013 at 8: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, 2013 at 8: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, 2013 at 8: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, 2013 at 8: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, 2013 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.