Multiple commands produce framework

Hello. My app is composed of multiple first party frameworks some of which depend on each other. Up until recently, they were all in a single workspace alongside the app, but I had to move them to separate repos in order to reuse some of them in a different app.

For simplicity, let's say that I have a Common framework and frameworks A, B and C that all depend on Common. The app itself also depends on Common.

I'm using Carthage for dependency management. I'm using it to build XCFrameworks. Everything is set up and the app builds and runs normally. However, since I want to be able to debug my frameworks from within the workspace of the app, I want to add the projects from the Carthage/Checkouts folder to the workspace. I can add the Common project this way just fine and everything works normally. However, as soon as I add a project that depends on Common (let's say B), Xcode starts spewing Multiple commands produce Common.xcframework when I attempt to build the app. Looking at the build logs I can see that it is trying to copy the Common.xcframework both from the Carthage/Build directory (which is the correct place to copy them from) AND the Carthage/Checkouts/B/Carthage/Build (which is the Carthage/Build directory of the subproject B). I cannot figure out why Xcode is attempting to copy from there. No target depends on the B subproject. The only thing that has a reference to the project is the .xcworkspace file. The build logs do not show that Xcode is trying to build the target of the B project.

I've also reproduced this in an empty app using the same frameworks. Can anyone explain why Xcode does this? Why is it attempting to copy frameworks from a place unrelated to the target it is currently building? And is there a way to get around this? Any pointers would be very welcome. Thank you.

Using Xcode 13.1

Same for me. Did you able to fix it?

For anyone struggling with this, I haven't been able to figure out why Xcode does this, but I've figured out a way to stop this from happening. When Carthage bootstraps it must set up every dependency in Carthage/Checkouts so that it can be built individually. Which means that for each dependency in Carthage/Checkouts, its own Carthage/Build folder must be populated and each of its dependencies in Carthage/Checkouts must be set up the same way and so on down the dependency graph.

So if we have an app which depends on frameworks A and B, but A also depends on B, after running carthage bootstrap, the directory structure should look something like this:

App/
  Carthage/
    Build/
      A.xcframework
      B.xcframework
    Checkouts/
      A/
        Carthage/
          Build/
            B.xcframework
          Checkouts/
            B/
      B/

Now, the problem is Xcode will try to copy both App/Carthage/Build/B.xcframework and App/Carthage/Checkouts/A/Carthage/Build/B.xcframework to the built products directory. So I tried just deleting any nested Carthage/Build directories in the dependencies in App/Carthage/Checkouts after running carthage bootstrap. And it worked. Those directories are only needed when building the dependencies anyway. After that is done, they are no longer needed. For clarity, this is how the directory structure looks after deleting the nested Carthage/Build directories:

App/
  Carthage/
    Build/
      A.xcframework
      B.xcframework
    Checkouts/
      A/
        Carthage/
          Checkouts/
            B/
      B/

One thing to note is that the nested Carthage/Build directories are actually symlinks to App/Carthage/Build. This is how Carthage builds each dependency in the dependency graph only once.

Multiple commands produce framework
 
 
Q