If you use additional files or libraries during development like HockeyKit or TestFlight you’ll want to exclude those in your production app store builds. Likewise, if you have an iPad and iPhone app that share the same Xcode project but are published under separate app IDs, this technique is handy for excluding iPad assets from your iPhone builds and vice-versa.
You won’t find this feature in Apple’s documentation. But it does exist in the form of a user-defined build setting called EXCLUDED_SOURCE_FILE_NAMES and it’s a really handy feature. I’ll use TestFlight in this example but you can use this approach to exclude any files from a build:
Excluding TestFlight’s shared library from the Release build configuration
- Open your project file. At the bottom of the screen click Add Build Setting -> Add User Defined Setting and name it EXCLUDED_SOURCE_FILE_NAMES.
- Click the arrow to the left of EXCLUDED_SOURCE_FILE_NAMES to expand it. In the Release configuration for this variable, add libTestFlight.a and any other files you’d like to exclude (separated by spaces).
Including TestFlight code only in the Debug build configuration
The problem now is that your release target won’t build. You need to surround any code that depends on the excluded files with a macro that checks to ensure it’s only included in the Debug configuration. You can use
#ifdef DEBUG for this, but in this case we’ll create a macro specific to TestFlight.
- Open your project file and navigate to Targets -> Your app target -> Build Settings -> Preprocessor Macros
- Add a new preprocessor macro
TESTFLIGHT=1to the Debug build configuration.
Now we’ll prevent TestFlight code from being compiled if the
TESTFLIGHT macro isn’t defined:
Now when you build your production binary, if all goes well, you’ll see that the resulting ipa file is quite a bit smaller since you’re no longer including libTestFlight.a!
Similarly, to exclude iPhone-specific files from your HD iPad builds, just add them to the
EXCLUDED_SOURCE_FILE_NAMES for your iPad build configuration.