Multiple configured targets of 'x' are being created for macOS

Since updating to Xcode 11.4, I can't build my mac catalyst app anymore:

multiple configured targets of 'SwiftPackage1' are being created for macOS

I don't find this error message very helpful for what I should do to fix this.

My app has 2 swift packages set to "iOS + macOS" and an iMessage app set to "iOS". Also, if I try to click delete on the swift package, Xcode just crashes instead...

2 Likes

Unfortunately, this is a known issue in 11.4.

@NeoNacho Do we know when that will be fixed?

He may not be able to tell you, as an Apple employee. Unless it's fixed in Xcode 11.5 (you should give it a try), we likely won't see a fix until Xcode 12 in the fall, if at all.

I see, thanks! I tried 11.5 but no luck. Looks like we have to wait for 12.

I narrowed down the cause further. The bug seems to be that the package is also being used by the iMessage app (even though the iMessage app is not for mac).

Workaround:
Delete the package from the iMessage app, and you can build the Mac app again. Then you can re-add the package to the iMessage app when you build for iOS.

1 Like

Experiencing the exact same error and landed here (Xcode 11.5). The suggestion to remove the framework from all other targets did work for me though of course it's a very annoying workaround and isn't going to work long term.

Edit: Can confirm this issue is fixed in Xcode 12

1 Like

I am starting seeing this problem for the first time in Xcode 12 beta 5. My package contains GUI elements, and it is when I try to view the GUI elements in the canvas that the error comes. It builds and runs fine on the real hardware, and also in the simulator.

Has anyone got an idea or workaround for this?

3 Likes

The issue still happens for me in Xcode 12.

There is an app and an app clip embedded into the app in my case, both have the same dependency. If the app is build for maccatalyst target - the error occurs. I guess removing the app clip solves the issue as it is not really needed for maccatalyst for now. But yeah, the error message is pretty confusing.

I could fix it with xcode 12.3

@doozMen great! Would you be so kind and share how you fixed it?

1 Like

deleting derived data fixed it for me

Did anybody ever find out what this message meant? I'm getting it now in the Xcode 14 beta, particularly when trying to use SwiftUI Previews

I've encountered this problem with building for previews and it's been much harder to work around in 14.0 than in older releases. In prior Xcodes, I was able to get previews to work with sufficient iterations of deleting DerivedData and dinking around with my package manifest. But I couldn't get it working at all (on my real production project) in Xcode 14.0 with just those actions.

I spent a while trying to find a minimal test case and eventually reduced it to a tiny SwiftPM package named MyPackage containing a single library target, MyLibrary, which includes a single module/target named MyTarget. (You can find my test project here.)

From there, a combination of two things led to the problem:

  • Having a resource (in my case, a xib) in the module, and
  • Manually creating the build scheme.

What I found was that an auto-created build scheme works, but the auto-created scheme contains three build targets:

  • MyLibrary,
  • MyPackage_MyModule, and
  • MyModule.

I can build for previews successfully with this scheme. But if I create a scheme manually, I cannot add all three of these targets to its build phase. The only target available to add to its build phase is MyLibrary. And that target alone is not sufficient; building for previews fails with the error “multiple configured targets of 'MyPackage_MyModule' are being created for macOS”.

Apple feedback report FB10114642 includes a video demonstrating the problem, in case anyone at Apple wants to investigate.

1 Like

I fixed it by cleaning Build Folder, fully exit Xcode and any simulators, reopen xcode and build for simulator again, close the app and go back to Xcode. Once that is complete reopen your canvas and press refresh/start and it should work again. (Assuming it's not an error elsewhere)

Seems like the simulator stores a reference to the package when my mac is put to sleep that is only released when fully exitted.

oof, so it sounds like Xcode bug that can't really be circumvented

@birtogamlo I tried every dance of cleaning the build folder, derived data, restarting, etc.

I'm not using the simulator, this is a pure macOS app

Looks like Xcode 14 beta 2 still has this issue

Have you tried comparing the XML of the auto-generated scheme vs your generation of it? Is there any difference?

If you look at the Package+Library+Module scheme in my sample project, you'll see that it has BuildActionEntry stanzas for MyModule and MyPackage_MyModule that are not in the Library-only scheme.

1 Like

Hey! I have the same problem when i use the new buildtool plugin system for generating assets via SwiftGen. (we took the sample implementation of @abertelrud as a guide)

Basically I have two SPM targets, where in one the assets are generated and a second target which imports the asset target.

		.target(
			name: "AssetKit",
			plugins: ["SwiftGenPlugin"]
		),
		.target(
			name: "Components",
			dependencies: ["AssetKit"]
		),

If I select the Components scheme in Xcode 14 and want to preview a SwiftUI view the following error
appears.

multiple configured targets of 'SwiftGenPlugin' are being created for macOS

----------------------------------------

SchemeBuildError: Failed to build the scheme "Components"

multiple configured targets of 'SwiftGenPlugin' are being created for macOS

Prepare build:
error: multiple configured targets of 'SwiftGenPlugin' are being created for macOS

I created a sample project to showcase the error (GitHub - aregler/SwiftGenPreview: An example for broken SwiftUI previews)

If somebody knows what I am doing wrong or how this problem can be fixed - any help would be very appreciated.

Have a nice day,

Arsatius

5 Likes