R.swift icon indicating copy to clipboard operation
R.swift copied to clipboard

Multiple commands produce 'xxx/RswiftGeneratePublicResources/xxx/R.generated.swift'

Open RobertDresler opened this issue 3 years ago • 8 comments

Hello,

I have iOS app which has embedded watchOS app. I also have SPM package which runs R.swift plugin:

.target(
    name: "VOSStrings",
    dependencies: [.product(name: "RswiftLibrary", package: "R.swift")],
    resources: [.process("Resources")],
    plugins: [.plugin(name: "RswiftGeneratePublicResources", package: "R.swift")]
)

This package is added to both targets: the main iOS app and its embedded watchOS app. Unfortunately, I am unable to build the app since I receive the error Multiple commands produce 'xxx/RswiftGeneratePublicResources/xxx/R.generated.swift'

Screenshot 2023-03-14 at 20 26 52

When I remove watchOS app from target dependencies of iOS app, it works, but then iOS app can't be built. Don't you know what could be wrong?

Thank you!

RobertDresler avatar Mar 14 '23 19:03 RobertDresler

i have the same error, but i delete old R.generated.swift file and then rebuild project success

SpectatorNan avatar Mar 16 '23 22:03 SpectatorNan

I use 7.3.0, which does not need to add R.geratated.swift to your target, only need to add script in accordance with SPM access steps to build and then R.xxx can used. It is worth noting that the name of the struct is changed to _R, and the Struct can extension with _R struct.

LP-sleep avatar Mar 17 '23 05:03 LP-sleep

@SpectatorNan unfortunetely, this doesn't solve the problem for me since I use SPM where storing this file is out of my control.

RobertDresler avatar Mar 20 '23 15:03 RobertDresler

@tomlokhorst here is minimal reproducible example. Don't you know, what could be wrong? https://github.com/RobertDresler/RSwift-in-shared-package

RobertDresler avatar Apr 13 '23 19:04 RobertDresler

Thanks for the minimal reproducible example, that is very useful!

I'm no expert on the Xcode build system, so I'm not exactly sure what's going on.

But I did manage to the the example building, with some changes:

  • I removed the reference to Strings from both targets
  • I added a new Framework target, that does use Strings
  • I included that new framework in both original targets

Again, I'm not exactly sure, but I think the difference with this indirection is that the new framework is dynamically linked, and the original Strings library was statically linked (twice).

tomlokhorst avatar Apr 16 '23 20:04 tomlokhorst

Anyone able to find the root cause of this issue?

saltyskip avatar May 08 '23 03:05 saltyskip

@saltyskip Creating two different targets overcomes the problem (see my question on SO). Eventough it doesnt solve it as I would like to, I don't know any better solution so far.

If you need to have targets A and A_watchOS, and you have target B which is imported by both iOS and watchOS app targets, you can create B which imports A and A_watchOS based on platform condition in SPM.

RobertDresler avatar May 12 '23 08:05 RobertDresler

This is a blocker for us. We have two schemes and one target. Fails because it thinks it needs to build for both schemes...

image

Reverting to R.swift 6.

realityworks avatar Jul 31 '24 23:07 realityworks