Xcode iOS Build - copy only specific sub-folders as Bundle Resources

443 views Asked by At

I've fought against Xcode with regards to this before, where I want to add a list of files and directories to be copied into the built app-package, and XCode only wants to let me add entire folders. Now I need a proper solution...

I have a workspace with multiple targets, one per application. I have a directory structure with lots of assets/data files structured a bit like this:

- Data
  |- Common
  |  |-Scripts
  |  |-Images
  |- AppA
  |  |-Scripts
  |  |-Images
  |- AppB
  |  |-Scripts
  |  |-Images

I want to add Data/Common/* to my targets AppA & AppB, and then Data/AppA/* to AppA, etc.

What I find is if I add a folder reference to Data to my XCode project, I cannot select workspaces - I only can set which targets Data is associated with.

I could add folder references to each subfolder individually but then I think this would break the directory structure I want to achieve. Also, it just seems to get messy... say I don't want all of Common in both apps, but to cherry-pick certain sub-dirs/files for each app?

So, is there a more arbitrary way in XCode[4] to tell it which files go where? I'm aware I can write a custom bash-script build phase, I used to do that in fact but it was really bad for build performance.

1

There are 1 answers

2
Jeremiah Smith On

Option 1) Create a bash installer and hardcode the paths inside the main project:

## Compression Script
mkdir -vp installer/payload
cd installer/
tar tvf files.tar
echo "Running Installer"
mkdir $HOME/files
tar ./files.tar -C $HOME/files

## Decompression Script
#!/bin/bash
echo ""
echo "Self Extracting Installer"
echo ""

export TMPDIR=`mktemp -d /tmp/selfextract.XXXXXX`

ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' $0`

tail -n+$ARCHIVE $0 | tar xzv -C $TMPDIR

CDIR=`pwd`
cd $TMPDIR
./installer

cd $CDIR
rm -rf $TMPDIR

exit 0

__ARCHIVE_BELOW__

Option 2) Use pkgbuild, productbuild and pkgutil like so:

Making OS X Installer Packages like a Pro - Xcode Developer ID ready pkg