Xcode 14 try to build all SPM when building swiftUI preview

HI, I have an issue displaying SwiftUI previews with Xcode 14.

My project has iOS and an watchOS Target. It also includes a lot of SPM, most of them only used by the PhoneApp. The project build successfully for both iOS and watchOS.

I can see that when building the watch target, only SPM that are included in this target are build for for watchOS

The issue is when I try to build a swiftUI preview of the watch target. In this case I can see on the build for Preview log that Xcode try to build ALL spm defined in the Xcode project, including the one that are not used by the watch Target, As a lot if spm are for iOS only, and doesn't build for watchOS, the build for preview fails, and I'm unable to preview my swiftUI views on the AppeWatch.

Note that my project is working fine on Xcode 13.

This issue is easy to reproduce in any Xcode projects containing a iOS and watchOS target by adding a SPM that is only for iOS.

Any workaround to fix this issue ?

Accepted Reply

This problem still exists in Xcode 14.3 (14E222b)

  • Just hit this... so there is no workaround? We just cant use swiftui previews with watch apps?

  • Same issue here :/

Add a Comment

Replies

We've heard feedback about this issue as well and are investigating it. If you can, do please file a radar about it. We can relate your information with our other efforts and you can get notified when it is fixed.

Feedback filled: FB11149104, with as sample project reproducing the issue.

I can confirm this issue on the latest Xcode 14.1 beta 3 (14B5033e).

I can confirm issue is in 14.1 (14B47)

  • This bug is still not fixed in Xcode 14.2 (14C18).

Add a Comment

This problem still exists in Xcode 14.3 (14E222b)

  • Just hit this... so there is no workaround? We just cant use swiftui previews with watch apps?

  • Same issue here :/

Add a Comment

I still have the same problem with the first Xcode 15 beta

  • Got a lot error in Xcode 15 beta 5 when watch target use canvas to show Swift UI preview.....

  • Still not work for Xcode 15 beta 6, please fix this bug.

Add a Comment

Version 14.3.1 (14E300c) still has the issue.

I still encounter this issue in the final version of Xcode 15.0 (15A240d). It would be great to have previews available on watchOS to help with complications and widget development.

  • I've also submitted a feedback report for this issue (FB13208693).

Add a Comment

Issue is still present in Xcode 15, it's easily reproducible if importing the Lottie framework via SPM in an iOS project with a companion Watch app. This just messes Xcode Previews for the Watch app view.

My "Watch App" target never includes Lottie as dependency, just the "iOS App". Both build correctly and load on Simulator devices. But fails on Apple Watch Preview, which out of nowhere assume Lottie is a dependency for the "Watch App" even though it's not added on the target scheme. #frustrating

==PREVIEW UPDATE ERROR:

SchemeBuildError: Failed to build the scheme ”Watch App”

While building for watchOS Simulator, no library for this platform was found in '/Users/.../SourcePackages/artifacts/lottie-spm/Lottie/Lottie.xcframework'. (in target 'Lottie' from project 'Lottie')

Build target Lottie:

I have the same issue using the latest Xcode 15.0.1 (15A507). Previews stop working if any dependency imported using the Swift Package Manager doesn't support watchOS, even if those frameworks (in my case Datadog and Lottie) are not directly linked or used in the watchOS target.

Since I'm still experiencing the same issue in Xcode 15.1, I've now also submitted feedback for this issue (FB13467714). It's quite ridiculous this hasn't been fixed yet.

Same here - really quite frustrating

Same here on XCode 15.2 - this is such an annoying issue, since any swift package breaks watchOS previews. In my case, that's Firebase.

@Developer Tools Engineer - any updates on this regression from XCode 13 to Xcode 15?

Filed FB13545393

Same here, 15.2 as well - just upgraded from 15.0 hoping for a fix, but same error.

My project is an older one (5 yrs), that's adapted over time from earlier versions of Xcode and watchOS app components. Any chance that this could be a cause - that manually adapting projects along the way could have introduced exposure to this error? Hard to think that everyone with an SPM package and a watch app would be experiencing this.

Also - anyone have any sense when this could have been introduced? I can't believe I've not had watch SwiftUI previews for the entirety of time that I've had swift packages...

Yea even building a new one causes this and I can't find any other info about it - basically, this worked in XCode 13, broke from XCode 14.2 ish on. Its currently broken now. What's happening is that XCode is attempting to link package sub dependencies to the selected preview scheme if you run on WatchOS (and I think on VisionOS too.) Its incredibly frustrating, since even though we're obviously not using those packages and they parent package is excluded, XCode still tries to link them. Simulators and real devices work fine.