8

I'm migrating my project from Carthage to SPM. I'm using Xcode 12.0. Building the main app works without any problems but I cannot run my unit tests anymore. I use the same framework SwiftDate v6.2.0 in both my App target (SPMD) and my App test target (SPMDTests).

I already resolved the Swift package product 'your library' is linked as a static library by 'your project' and 'your widget'. This will result in duplication of library code.. I followed the tutorial Swift Package Manager Static Dynamic Xcode Bug.

I can run my app but I cannot run my unit tests. The error says

Unexpected duplicate tasks:
1) Target 'SPMDTests' (project 'SPMD') has copy command from 'xxx/DerivedData/xxx/Build/Products/Debug-iphonesimulator/SwiftDate_SwiftDate.bundle' to 'xxx/DerivedData/xxx/Build/Products/Debug-iphonesimulator/SPMD.app/PlugIns/SPMDTests.xctest/SwiftDate_SwiftDate.bundle'
2) Target 'SPMDTests' (project 'SPMD') has copy command from 'xxx/DerivedData/xxx/Build/Products/Debug-iphonesimulator/SwiftDate_SwiftDate.bundle' to 'xxx/DerivedData/xxx/Build/Products/Debug-iphonesimulator/SPMD.app/PlugIns/SPMDTests.xctest/SwiftDate_SwiftDate.bundle'

1

2

I tried the same setup with Realm and it works without any problems. Is this a bug with SwiftDate or am I missing anything?

Yannick
  • 3,210
  • 1
  • 21
  • 30

1 Answers1

3

There seems to be a bug in the implementation of Swift Packages that include resources in Xcode 12 (also in Xcode 12.2 beta).

This issue will only arise if you have a dependency on a package that has resources (SwiftDate does) in both your main target and your unit test target. This bug only seems to affect compilation of the unit test target, so the main app target should still compile successfully.

Eric Yanush
  • 384
  • 1
  • 6
  • 1
    Yes, it only affects my unit test target. Do you know if an official bug report exists? – Yannick Oct 01 '20 at 08:44
  • I've opened a feedback report (FB8751233) a few days ago, so far there has been no response. I believe this is a bug in the "new build system" in Xcode and how it has implemented handling of swift packages that contain resources, so I did not open a bug report on the open source project bug tracker. – Eric Yanush Oct 01 '20 at 17:52
  • I am facing the same issue, did you find a way to workaround it? – Lucas Lima Oct 09 '20 at 13:07
  • I haven't found a way to work around the issue, and I'm not sure there is one, other than to copy all your code into one package. Since you're encountering the same issue, I would suggest that you also open a bug report with Apple (using Feedback Assistant) as more feedback reports help the issue gain visibility at Apple. – Eric Yanush Oct 14 '20 at 14:26
  • 4
    Just relying on SO as well, we're seeing the same problem, and have filed both a radar and https://bugs.swift.org/browse/SR-13739 – Claus Jørgensen Oct 15 '20 at 12:55
  • 1
    I also opened a feedback, no response yet from Apple. – hakkurishian Oct 28 '20 at 10:17