Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package Loading: "Ignoring duplicate product" (SwiftPM)

I'm trying to build a Swift package using the Swift Package Manager.

However, when I open the package in Xcode and click Run, I get the following warning:

enter image description here

How can I resolve this?

like image 742
Vatsal Manot Avatar asked Aug 18 '19 15:08

Vatsal Manot


2 Answers

This is an issue often encountered if you are attempting to build a library/framework but also have a main.swift file in your target's root directory, like so:

enter image description here.

The presence of a main.swift file makes SwiftPM believe that you are attempting to build a command line tool, and thus complains about the unnecessary (duplicate in name) library produced.

This warning may be confusing as it does not occur in projects initialized with the dynamic framework template from Xcode, for iOS, macOS, tvOS or watchOS.

like image 166
Vatsal Manot Avatar answered Nov 08 '22 23:11

Vatsal Manot


In my case it was because I had the same name in both the products section and the Package e.g.

let package = Package(
    name: "Example",
    products: [
        .library(
             name: "Example",
             targets: ["Example"]),
    ],
)

This seems to be the default behavior of swift init for some reason. I removed the .library entry and the warning went away.

like image 43
jlyonsmith Avatar answered Nov 09 '22 00:11

jlyonsmith