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
,Release
MyProduct (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
Debug
toDebug Staging
- I changed
Release
toRelease 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
Debug
andRelease
configuration anymore. After runningpod install
I could see actually 6 build configurations for the Pods Xcode project:Debug
Debug Staging
Debug Production
Release
Release Staging
Release Production
Solution
I decided to use
Debug
andRelease
for the Production environment andDebug Staging
andRelease Staging
for the staging environment. I ranpod install
again and: Problem solved. I see 4 build configurations for the Pods project:Debug
<-- ProductionDebug Staging
Release
<-- ProductionRelease Staging
All the custom frameworks build again successfully and I can run my unit tests again.