iosxcodecocoapodsbuildconfigurationswift-custom-framework

Custom Xcode Build Configurations with Custom Frameworks and Cocoapods


I have a project with a main iOS target, some custom frameworks whose source files are in the same project, and CocoaPods.

I recently changed my Xcode build configuration names and added two more in order to cover two environments (staging, production) plus debug and release configuration for each environment.

Two targets for Staging and Production

I was so annoyed by having to check two targets in the save dialog every time. I decided to have only one target but multiple build configurations. And surprisingly you can do pretty much everything with build configurations and variables in your Info.plist files.

Two build configurations per Environment

So I changed the configurations like so:

  1. I changed Debug to Debug Staging
  2. I changed Release to Release Staging
  3. I added Debug Production
  4. I added Release Production

I needed to update the scheme settings, too, to use the correct config.

Since you change the configuration in the project and not in the individual targets, all targets will get these configurations.

Problem with Custom Frameworks and CocoaPods

Since I'm using CocoaPods I ran pod install to generate the configurations for the Pods as well. It succeeds and I can build and run my main target with different configurations.

The problem now is that I can neither build my custom frameworks individually anymore, nor their unit tests. I'm getting errors like these:

  • Command MergeSwiftModule failed with a nonzero exit code
  • Framework not found "Pods_MyProject"

I've tried already everything from cleaning derived data to deintegrating CocoaPods.


Solution

  • Turned out Cocoapods gets somehow confused when there is no default Debug and Release configuration anymore. After running pod install I could see actually 6 build configurations for the Pods Xcode project:

    Solution

    I decided to use Debug and Release for the Production environment and Debug Staging and Release Staging for the staging environment. I ran pod install again and: Problem solved. I see 4 build configurations for the Pods project:

    All the custom frameworks build again successfully and I can run my unit tests again.