I am working on rebuilding our large app's dependency graph to use Swift Package Manager, replacing CocoaPods. I have it nearly done and am quite happy with the progress so far. However, I've run into a blocker with Xcode's SwiftUI Previews not working, seemingly due to several .binaryTarget dependencies.
I've boiled this down to a simple reproducible case, with this Package.swift:
Here I am using NewRelic as a common 3rd party dependency that vends an .xcframework.zip-- but this is not specific to NewRelic and can be reproduced with many (any?) similar examples.
This package builds a library successfully and works as expected when included in an app.
But when I try to use SwiftUI previews on a trivial view, e.g.:
I end up with this Unexpected duplicate tasks build failure, due to the build system seemingly trying to process the XCFramework twice:
I've posted the reproduction case on GitHub here. Tested with Xcode 12.5 Beta 3.
https://github.com/mthole/DuplicateTasksOnPreview
I've boiled this down to a simple reproducible case, with this Package.swift:
Code Block let package = Package( name: "MyLibrary", platforms: [.iOS(.v13)], products: [.library(name: "MyLibrary", targets: ["MyLibrary"]),], dependencies: [], targets: [ .target(name: "MyLibrary", dependencies: ["NewRelic"]), .binaryTarget(name: "NewRelic", url: "https://download.newrelic.com/ios_agent/NewRelic_XCFramework_Agent_7.3.0.zip", checksum: "daaaff7897246e4baddb1b8131a79268de3b6889a48182b4fbdabe5b926d08f4"), ] )
Here I am using NewRelic as a common 3rd party dependency that vends an .xcframework.zip-- but this is not specific to NewRelic and can be reproduced with many (any?) similar examples.
This package builds a library successfully and works as expected when included in an app.
But when I try to use SwiftUI previews on a trivial view, e.g.:
Code Block struct MyLibraryView: View { var body: some View { VStack { Text(verbatim: "Hello World, I'm MyLibraryView") } } } struct MyLibrary_Previews: PreviewProvider { static var previews: some View { return MyLibraryView() } }
I end up with this Unexpected duplicate tasks build failure, due to the build system seemingly trying to process the XCFramework twice:
Code Block note: Using new build system note: Building targets in parallel note: Planning build note: Using build description from memory note: Using build description 'e8ea061fcc823688d24edc3f230a0c7c' note: Build preparation complete note: Target dependency graph (3 targets) MyLibrary in MyLibrary MyLibrary in MyLibrary, depends on: MyLibrary in MyLibrary (explicit) MyLibrary in MyLibrary, depends on: MyLibrary in MyLibrary (explicit) error: Unexpected duplicate tasks: 1) Command: ProcessXCFramework /Users/mthole/Library/Developer/Xcode/DerivedData/DuplicateTasksOnPreview-bkclfnyhkfofwaaulhpstpdjggqb/SourcePackages/artifacts/DuplicateTasksOnPreview/NewRelic.xcframework ios simulator 2) Command: ProcessXCFramework /Users/mthole/Library/Developer/Xcode/DerivedData/DuplicateTasksOnPreview-bkclfnyhkfofwaaulhpstpdjggqb/SourcePackages/artifacts/DuplicateTasksOnPreview/NewRelic.xcframework ios simulator
I've posted the reproduction case on GitHub here. Tested with Xcode 12.5 Beta 3.
https://github.com/mthole/DuplicateTasksOnPreview