WatchOS Preview fails to compile when Swift Packages are added for iOS

When attempting to load a SwiftUI canvas for my watchOS app, it fails to load because Xcode attempts to compile the Swift Packages that are meant for iOS against the watchOS sdk.

Error examples:
"While building for watchOS Simulator, no library for this platform was found in 'ABC.xcframework'" for a framework

"Cannot find type 'UITableViewController' in scope" for packages that are all swift source code (UITableViewController is not available in watchOS)

Related Firebase sdk thread: SwiftUI previews breaks when adding a watchOS target · Issue #7610 · firebase/firebase-ios-sdk · GitHub

Is there a workaround for this issue?

4 Likes

Did you ever find a solution for this?

I've run into this same (or similar) issue:
I have an iOS app with watchOS app and a single Swift Package (SwiftMQTT). All Previews fail with a message stating that a file in the SP (getStreamsToHost) is unavailable in watchOS. The SP is not referenced from any watch app file though.
The Firebase thread referenced above stated that the problem was fixed in Xcode 13, but I am running on Xcode 14.2. Has the problem been regressed?

I'm running into this too on Xcode 15, did anyone find anything?

Running Xcode 15.2. Same problem with visionOS

You can try removing your ios target from the watch scheme in Xcode. This seems to allow previews to build but I am not sure what other consequences that may have yet. I recently posted this question and filed an apple issue here