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
MyProduct (Staging)with default configurationsDebug,ReleaseMyProduct (Production)with default configurationsDebug,Release
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:
- I changed
DebugtoDebug Staging - I changed
ReleasetoRelease Staging - I added
Debug Production - 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.
Turned out Cocoapods gets somehow confused when there is no default
DebugandReleaseconfiguration anymore. After runningpod installI could see actually 6 build configurations for the Pods Xcode project:DebugDebug StagingDebug ProductionReleaseRelease StagingRelease ProductionSolution
I decided to use
DebugandReleasefor the Production environment andDebug StagingandRelease Stagingfor the staging environment. I ranpod installagain and: Problem solved. I see 4 build configurations for the Pods project:Debug<-- ProductionDebug StagingRelease<-- ProductionRelease StagingAll the custom frameworks build again successfully and I can run my unit tests again.