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.

1

There are 1 best solutions below

6
On

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 {
// ...