Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode cannot generate Swift UI preview - build aborted due to an internal error: planningFailed

I'm using Xcode 12 beta 2. I've packaged my libraries in Swift Packages. DataModel that appear in the error message is one of them, that my current package, WeatherView depends on.

I can build the package fine, but Swift UI preview fails
enter image description here

build aborted due to an internal error: planningFailed("multiple configured targets of \'DataModel\' are being created for iOS Simulator")

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

SchemeBuildError: Failed to build the scheme "WeatherView"

unexpected service error: build aborted due to an internal error: planningFailed("multiple configured targets of \'DataModel\' are being created for iOS Simulator")

Build system information:
error: unexpected service error: build aborted due to an internal error: planningFailed("multiple configured targets of \'DataModel\' are being created for iOS Simulator")
like image 502
Guig Avatar asked Jul 10 '20 02:07

Guig


2 Answers

I found out that making the product library "dynamic" (instead of static) made my previews work from inside the package's targets.

let package = Package(
    name: "Modules",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        .library(
            name: "Modules",
            type: .dynamic,
            targets: ["App"]
        ),
    ],
    dependencies: [],
    targets: [
        .target(
            name: "App",
            dependencies: []
        ),
        .testTarget(
            name: "AppTests",
            dependencies: ["App"]
        ),
    ]
)

One must also declare the package's platforms.

like image 183
cicerocamargo Avatar answered Oct 18 '22 00:10

cicerocamargo


I got this same error when trying to preview my SwiftUI canvas for a view. I had multiple tabs open in Xcode. I closed all the other tabs but the one with my view and my canvas previews started working again.

like image 3
Kevin Avatar answered Oct 18 '22 00:10

Kevin