Hi, exactly same issue !
I'm experiencing the same issue.
I think that you should indeed be using a dynamic library - by setting the product type of your SPM library to `.dynamic`.
However, I have a similar example where I have a framework and a command-line app, both of which use a couple of SPM libraries. I've got both a static and a dynamic product defined in the SPM libraries, and have added the dynamic versions to the Link Binary With Libraries panel for both the framework and the command line target.
And I'm still getting the above error with Xcode 11.4b1!
Xcode 11.3.1 will build successfully, but I'm getting a runtime error about symbols being duplicated, so it looks like Xcode is actually ignoring the fact that I've added the dynamic versions to my targets, and is using the static versions instead.
Actually, after further investigation, I think that XC11.4 was correct in saying that I had a library linked twice. I was depending on other libraries which were pulling in the static version of the shared library. This is a real mess for any non-trivial graph .
What we really need here is for SPM's `.automatic` product type to work, and do the right thing!
Happening to me as well
I think i had the same problem.. it worked in XC 11.3.1 and 1.4 beta broke it...
Now I'm not a 100% on this but i think it was because i used SwiftPackages by locally importing them to XC (via Drag&Drop, as shown @ WWDC). Now for some reason XC didn't quite get that I wanted to use those local packages INSTEAD of the remote ones so in some projects it kept the remote ones wheras in other targets (SiriKit extension, if that matters) it used the local ones and therefore had two different, yet same packages...
So I removed the remote ones in Project Settings > Swift Packages and added the local ones to all my targets again.. Now it works...
Hope it helps someone ^^
This error still appears in Xcode 11.4 beta 4. It seems to happen when the main target A imports another target B, a dynamic framework, and both of them import a static library C.
A -> B
A -> C
B -> C
It seems like removing the static library C dependency from the main target A solves the issue.
Updated dependency graph:
A -> B
B -> C
Hope this helps!
This is still a problem with Xcode 11.4 beta 3 (11N132i)
I use SPM to import two 3rd party packages.
They are each needed both in the iOS App and an accompanying share extension.
I do not know how to resolve this.
Same issue. Trying to add Alamofire 4.9.1 (fairly well-known library supporting both Cocoapods and SPM).
Same here :/ Is there any solutions ?
error: Swift package product 'Disk' is linked as a static library by 'Project' and 'Widget'. This will result in duplication of library code.
I solved thanks to cocoapods. I installed them with cocoapods instead of package manager. Now it is building without errors.
Still not fixed in final Xcode 11.4, this is definitely a bug, either in SPM or Xcode.
I had the same problem, here's what fixed it for me in Xcode 11.4:
1. explicitly set `type` to `.dynamic` for all `products` in "Package.swift":
.library( name: "XXX", type: .dynamic, // add this targets: ["XXX"] ),
2. re-add SPM libraries in Project / Target / Frameworks and Libraries:
- what used to be "XXX" - "Do Not Embed"
- now becomes "XXX" - "Embed & Sign"
After these changes, build & run on device and simulator works, along with archive & export, although I had some errors when exporting until I restarted Xcode and started over, after which it succeeded.
Btw, my setup is a workspace which contains:
- Single Swift package ("XXKit") with multiple targets (modules), defining multiple products (libraries)
- Main project with multiple targets (iOS app, Widget, Extensions) linking libraries from the "XXKit" package
- Pods project (for 3rd party stuff which still doesn't support SPM)
My project in an existing (pre Xcode 11.4 and pre-SPM). I used Xcode 11.4 to open the project, and added a package via the Xcode UI.
I couldn't find anywhere a generated Package.swift file to edit. It seems as these references are in the .xcodeproj file.
Thanks for the help, I used the
tips, and it works, thankfully because the two libraries I used was mine, so it's ok. But I think it's not a solution.
If you don't precise a type, Xcode should be smart enough to guess if it has to use either a dynamic or a static library, right? So why it's mendatory to explicit that in the package.swift of the library itself.
I would rather like to have an option in Xcode to use the library as dynamic rather than putting that in the library definition
Using 3rd party packages, can't fix by the dynamic type since packages are added in Xcode UI. Definitely a bug in Xcode 11.4.
It would be great to get official advice on this. Having an extension that depends on the same third party lib as the main target isn't unheard of. It seems this should have never worked in the first place (which is fine), but then it's not nice to break this without a workaround.
I've moved most dependecies to SwiftPM, but still have cocoapods around so I've brought all dependecies that I use in extensions back to cocoapods.
This is still happening with the official release of Xcode 11.4. Obviously we don't have control over 3rd party packages to change static to dynamic, and of course many libraies are shared across targets and extensions. Please don't say this is a feature