0

I'm creating a watchOS app which depends on an iOS app. Both those apps have their corresponding targets. Both targets link my local SPM library, which have single target. This target calls R.swift plugin which generates file in the output directory.

Unfortunately, I got the following error when I try to build the app:

Multiple commands produce '/Users/XXXX/Library/Developer/Xcode/DerivedData/watchOSTestPAckage-aqjgymttvegntyaogebiuclgbsyb/SourcePackages/plugins/resources.output/Strings/RswiftGeneratePublicResources/Strings/R.generated.swift'

enter image description here

I know that this error is connected with one specific library, but the error can occur also sometime in the future in other similar cases.

Here is minimal reproducible example: https://github.com/RobertDresler/RSwift-in-shared-package

Don't you know, what could cause this problem? Thank you for any help with solving this.

Robert Dresler
  • 10,580
  • 2
  • 22
  • 40

1 Answers1

1

Edited

In your Package.swift, you need to declare: Strings_watchOS as a library:

    // ...
    products: [
        .library(
            name: "Strings",
            targets: ["Strings"]
        ),
        .library(
            name: "Strings_watchOS",
            targets: ["Strings_watchOS"]
        )
    ],
    // ..

then link it to watchOSTestPAckage Watch App:

enter image description here

and import it in your watchOSTestPAckageApp.swift:

import SwiftUI
import Strings_watchOS

@main
struct watchOSTestPAckage_Watch_AppApp: App {
// ...
AnderCover
  • 2,488
  • 3
  • 23
  • 42
  • Thank you for helping. However, this doesn't solve the problem since now there isn't `Strings` linked to the watchOS target. I updated my code with needed imports and as you can see, it has to be linked to the watchOS target. – Robert Dresler Apr 17 '23 at 06:18
  • I edited my answer and it compiles. I hope this time the provided example is truly minimal and reproducible. – AnderCover Apr 17 '23 at 09:50
  • 1
    Yep, this is solution which I used in the end. However, this requires you to have duplicated targets, which you have to maintain simultaneously so you can't reuse the code. I feel like there has to be clearer way. – Robert Dresler Apr 17 '23 at 11:56
  • I don't think there's another way. The error messages are saying it has to do with the script phase. That's the plugin – AnderCover Apr 17 '23 at 17:39
  • 1
    what do you think about this response from library maintainer https://github.com/mac-cain13/R.swift/issues/815#issuecomment-1510485526 ? – Robert Dresler Apr 18 '23 at 06:16
  • "and the original Strings library was statically linked (twice)" yes that is why it works with `Strings_watchOS`. I did not try his approach with the dynamic frameworks but it seems like a good idea. – AnderCover Apr 18 '23 at 07:48