Slim down your iOS app by excluding files from production builds

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

  1. 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.
  2. 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.

  1. Open your project file and navigate to Targets -> Your app target -> Build Settings -> Preprocessor Macros
  2. Add a new preprocessor macro TESTFLIGHT=1 to the Debug build configuration.

Now we’ll prevent TestFlight code from being compiled if the TESTFLIGHT macro isn’t defined:

[TestFlight takeOff:@"testflightkey"];

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.

3 thoughts on “Slim down your iOS app by excluding files from production builds

    • Jules, do you mean the build configuration name? It depends how your project is set up. The defaults for an iOS project are Debug and Release, and people generally use the Debug configuration for testing and the Release configuration for app store submissions. Most mature projects will have more build configurations. The point is that you don’t want to compile code in a configuration that doesn’t include the supporting files.

  1. When I archive my build, and then share, select either release or debug ( pr for me ad-hoc) and save the file.

    Shouldn’t the release file be a smaller file than the debug / adhoc file ?


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>