2

I'm unable to get Xcode to copy over www resources to my PhoneGap based iPhone app. I considered using Git submodules, but since the app has to work on different platforms (iPhone, Android, etc) and has to be branded differently (images, css, and small changes to some files), it does not solve the complete problem.

I ended with a solution where I created an external core www folder and created symlinks for every file from the different projects. If a file needed special attention on a platform or for a branding requirement, then I could simply replace that instance of a symlink with an actual file.

This all would work like a charm, but for some reason Xcode for does not copy the symlinked resources over to the phone. Does anyone have any idea how to make this work? Or a solid alternative. Even if this takes me a day to fix.

Thanks.

Jack
  • 16,506
  • 19
  • 100
  • 167

2 Answers2

8

This solution worked perfectly to pull in the symlinks on build. Using this method you can build Phonegap solutions for all platforms and have them branded differently with the absolute minimum code duplication.

In short, create a common directory that contains all your phonegap www contents, and then symlink this from your different projects (platform differences or branding differences). For building on Xcode, add the following to your project's run script:

rsync -pvtrlL --cvs-exclude \
    $PROJECT_DIR/../Resources* \
    $BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH

Note: You also need to dereference symlinks if you build for BlackBerry.

Community
  • 1
  • 1
Jack
  • 16,506
  • 19
  • 100
  • 167
  • additional info on adding a build script phase for those who are in the dark: http://runscriptbuildphase.com/ – scald Aug 18 '12 at 02:38
  • this doesn't work for me... I get told the `Resources` directory doesn't exist. Should I be updating that to where I want my files copied - as in `www/mysubmodule`. I don't fully get what's happening though. Is it copying the files into the resources folder? I'm also sym-linking to a git submodule which will be confusing things further I guess. – Pete Nov 10 '12 at 00:38
  • The example above uses XCode project environment variables. So you could have done everything manually from the command line (terminal) with something like: rsync -pvtrlL --cvs-exclude [path to source directory] [path to target directory]. rsync is just a unix command, and the specific parameters you are giving it, is telling it to copy over the actual files, and not the symbolic links. – Jack Nov 10 '12 at 06:42
  • 1
    I got it, it was more like this for me `rsync -pvtrlL --cvs-exclude \ $PROJECT_DIR/../public_html/mobile* \ $BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/www` - they key point being I had to put the www on the end – Pete Nov 30 '12 at 15:23
  • I put my run script directly after the "Copy www directory" build phase. My symlink is a src folder "www/src" so I used this command: `rsync -pvtrlL --cvs-exclude \ $PROJECT_DIR/../../src* \ $BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/www` – wtjones Sep 06 '13 at 01:22
2

I just want to say that using symbolic links shouldn't be necessary. You can simply drop the folder into xcode, and DO NOT copy the files.

In my case, my shared folder was called "mobile", so I did have to create this run script:

mv $BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/mobile $BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/www

This simply renames the directory so Cordova can find what it's looking for.

bearfriend
  • 10,322
  • 3
  • 22
  • 28