2

I am looking for some documentation or tutorial for copying files from a given directory into the app created by xcode at build time, before it is run. At first I have tried to copy files into the derived directory, hoping that everything resides in there would be automatically added to the app, but I was wrong.

So I am looking for a script because the original dir may change its name, second the script could be customized by another xcode 4 user with its src dir path etc. The things is I don't know how to start, which language etc. I am quite confident with shell script, but maybe there's a better option. Second, I am trying to figure out which command could add a file in the already built app.

thanks

Leonardo
  • 9,607
  • 17
  • 49
  • 89

2 Answers2

2

That answer didn't really help - the BUILT_PRODUCT_DIR isn't where most stuff goes.

Ultimately, I found you just need to do:

  1. Add the following to the very end of your script (or get your script to write directly to the output location):

    cp ${DERIVED_FILE_DIR}/[YOUR OUTPUT FILES] ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}

...but there's a lot of other things I tried. More thoughts and ideas here: http://red-glasses.com/index.php/tutorials/xcode4-a-script-that-creates-adds-files-to-your-project/

Adam
  • 32,900
  • 16
  • 126
  • 153
1

You want a Run Script or Copy Files build phase. Select your main project in the navigator, then select the app's target. Click the Build Phases tab. Click the Add Build Phase button at the bottom of the window and choose the appropriate phase.

By "appropriate" I mean if you really want to run a script, you'll use a Run Script build phase and use Xcode-provided environment variables like $BUILT_PRODUCT_DIR (see the documentation or hit build and examine the full output of an empty script in the build log) to figure out your target folder. If all you want to do is copy files (no real processing), the Copy Files build phase already knows how to locate the app bundle's proper folders depending on what you're copying (Resources, Frameworks, etc.).

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • thanks, in particular this was the last options I wanted to use for this question, where copy files phase is not working: http://stackoverflow.com/questions/6690080/how-to-include-a-bundle-in-main-project-xcode-4 since I got no answer (even my official Apple ticket incident is still open). So I am really going for a "copy" script. – Leonardo Aug 03 '11 at 13:11
  • Okay. An attempt at an answer was posted for your original question. This one does answer the question you asked, though, so close out this one and keep going with the other. – Joshua Nozzi Aug 03 '11 at 13:21
  • I have just tried and it works, but I don't know if I am doing right, because I am copying directly in the products itself, which is basically what I was doing manually in xcode. I did cp -r $BUILT_PRODUCTS_DIR/mybundle.bundle $BUILT_PRODUCTS_DIR/myapp.app – Leonardo Aug 03 '11 at 18:31
  • also, a little O.T. I also tried to run the script in manage schemes section, both pre and post built, but the script didn't get called. – Leonardo Aug 03 '11 at 18:32