Andreas
Andreas

Reputation: 10067

Copy build to a different directory after finishing building

When I build my project with Xcode 8, it saves the final build in ~/Library/Developer/Xcode/DerivedData/MyProject-[add-lots-of-random-chars-here]/Build/Products/Release-iphoneos. Is there any way to make Xcode copy the app bundle to a user-specified path after building it? e.g. how can I make Xcode copy the built app bundle to /MyBuilds after building it?

I know that I can change the path for storing derived data in my project's settings in Xcode but doing so will of course make Xcode store all data (including intermediate stuff like object code etc) in this location which I don't want. I really only want Xcode to copy the final, ready-for-distribution app bundle to a user-specified location without any intermediate files used in the build process.

How can I do that?

Upvotes: 1

Views: 1889

Answers (2)

John
John

Reputation: 8548

The solution using a script in "Build Phases" does not work properly since Xcode is not finished building the app when running the script. Here is a solution with a script that runs after all build tasks are finished:

  1. Go to "Edit Scheme"
  2. Click on the triangle next to "Build"
  3. Select "Post-action"
  4. Press the + button and select "New Run Script Option"
  5. Select your app name in "Provide build settings from"
  6. Add the following shell script:

Script:

PRODUCT="${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app"
cp -R "${PRODUCT}" ~/Desktop

Edit Schemes

Upvotes: 5

shallowThought
shallowThought

Reputation: 19602

Add a shell script to your build phases to copy the product:

Script:

PRODUCT="${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app"
cp -R "${PRODUCT}" ~/Desktop

Certainly replace ~/Desktop with a target directory of your choice.

Upvotes: 3

Related Questions