App compiles and run for Debug, but fails to link for Release on unused dependency

So I'm working on a large client app with lots of frameworks and modules which is is a mix of Xcode frameworks with 3rd party dependencies in CocoaPods and newer/converted SPM modules. Essentially CocoaPods is used to set the 3rd party dependencies on various Xcode frameworks, which also depend on each other via manual set dependencies, plus a bunch of SPM modules which are also manually added. It's a bit of a mess.

The problem we encountered the other day started when I added a new protocol to one of the SPM modules. Nothing special about it, all types from Foundation and the app built and ran perfectly in simulator with a Debug build.

However when we switched to building a Release build, it failed to link, logging an error indicating it could not resolve the new protocol in a number of the Xcode framework projects.

The resolutions go like this:

  1. The Xcode app project has some manually added Xcode frameworks.
  2. Those frameworks have manually added dependencies on a second Xcode framework.
  3. That second framework has an SPM dependency on the module where my protocol lives.

So Xcode App -> 1st Xcode framework -> 2nd Xcode framework -> SPM module.

Now the 2nd Xcode framework directly uses my protocol from the SPM module. But the 1st Xcode framework neither uses or imports the SPM module.

Yet the error we get when building for Release is that the 1st Framework is unable to resolve the protocol from the SPM module even though it's completely oblivious to it.

My working theory is that something in the way a Release build works is insisting that when linking the 1st Xcode framework, it has to resolve the 2nd Xcode framework, which then has to resolve types from the SPM modules, but for some reason and only in a Release build, it's unable to.

So our current workaround has been to add the SPM module as a dependency to all 1st level Xcode frameworks that have the 2nd Xcode framework as a dependency. That works because when linking the 1st Xcode framework, it has a direct reference to the module even though the code never imports anything from it.

Does this should correct?

There are multiple ways to configure this, so I can't say what's correct and what's happening in your original setup without seeing an example. Do you get the same error with just the relevant code in a small test project that models your original project's dependency setup? If so, please share a link to your test project. That'll help us better understand what's going on. If you're not familiar with preparing a test project, take a look at Creating a test project.

—Ed Ford,  DTS Engineer

App compiles and run for Debug, but fails to link for Release on unused dependency
 
 
Q