Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple commands produce (...) Xcode 11, using 2 targets #560

Closed
narlei opened this issue Sep 25, 2019 · 7 comments
Closed

Multiple commands produce (...) Xcode 11, using 2 targets #560

narlei opened this issue Sep 25, 2019 · 7 comments

Comments

@narlei
Copy link

narlei commented Sep 25, 2019

My project use 2 targets MyApp and MyAppDev both has the R.swift script to generate the file.
After Xcode 11 I'm receiving this error when I try run with fastlane.

❌ error: Multiple commands produce '/Users/narlei/sources/ios/mobile-app-ios/MyApp/R.generated.swift':

duplicate output file '/Users/narlei/sources/ios/mobile-app-ios/MyApp/R.generated.swift' on task: PhaseScriptExecution R.swift /Users/narlei/Library/Developer/Xcode/DerivedData/MyApp-gzdqbugguohnkhdzzsdvsiatbckl/Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/MyAppDev.build/Script-9C71E27C2177BE4D006F5B7E.sh (in target 'MyAppDev' from project 'MyApp')

Testing failed:
Multiple commands produce '/Users/narlei/sources/ios/mobile-app-ios/MyApp/R.generated.swift':

  1. That command depends on command in Target 'MyApp' (project 'MyApp'): script phase “R.swift”

  2. That command depends on command in Target 'MyAppDev' (project 'MyApp'): script phase “R.swift”

    Testing cancelled because the build failed.

@RodrigoLGuimaraes
Copy link

The same happened here. My solution was to create a different generated file for each target, so ultimately I got:

A) For the production environment the script is:
"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.generated.swift"
And the output files are: $SRCROOT/R.generated.swift

B) For the staging environment the script is:
"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.staging.generated.swift"
And the output files are: $SRCROOT/R.staging.generated.swift

Upon changing, I had to rebuild the project in each target, add the newly generated R.staging.generated.swift to the project in the staging target and change the old R.generated.swift to be only used by my default target.

At least for now, this seems like it solved it, if you guys find any drawbacks on the solution let me know :)

@narlei
Copy link
Author

narlei commented Sep 25, 2019

@RodrigoLGuimaraes For me, using the Legacy Build System works, the bug is only with New Build System.

@branohricardo
Copy link

I experienced the same issue, however, I believe that the problem is not really on the R.swift side but rather in your project configuration.
In my case, the project has also a target for MyAppUITests. In your scheme configuration that builds MyAppDev target (Edit scheme -> Build), you'll have most likely also the MyAppUITests target. If your MyAppUITests target has a MyApp dependency then you're building both targets in one step which results in generating twice the R.generated.swift and results in this error.

@narlei narlei closed this as completed Oct 29, 2019
@onmyway133
Copy link

For me, I have R.swift build phase in 2 targets. Removing it in 1 works for me

@akatao
Copy link

akatao commented Aug 4, 2020

@RodrigoLGuimaraes Monster Kill!!!! Best Answer! Saved my life today!

The same happened here. My solution was to create a different generated file for each target, so ultimately I got:

A) For the production environment the script is:
"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.generated.swift"
And the output files are: $SRCROOT/R.generated.swift

B) For the staging environment the script is:
"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.staging.generated.swift"
And the output files are: $SRCROOT/R.staging.generated.swift

Upon changing, I had to rebuild the project in each target, add the newly generated R.staging.generated.swift to the project in the staging target and change the old R.generated.swift to be only used by my default target.

At least for now, this seems like it solved it, if you guys find any drawbacks on the solution let me know :)

@Knicks135
Copy link

Knicks135 commented Jan 14, 2021

@RodrigoLGuimaraes Monster Kill!!!! Best Answer! Saved my life today!

The same happened here. My solution was to create a different generated file for each target, so ultimately I got:
A) For the production environment the script is:
"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.generated.swift"
And the output files are: $SRCROOT/R.generated.swift
B) For the staging environment the script is:
"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.staging.generated.swift"
And the output files are: $SRCROOT/R.staging.generated.swift
Upon changing, I had to rebuild the project in each target, add the newly generated R.staging.generated.swift to the project in the staging target and change the old R.generated.swift to be only used by my default target.
At least for now, this seems like it solved it, if you guys find any drawbacks on the solution let me know :)

Yeah totally saved me too. I really think this should be in the main page of the FAQS within the documentation on how to integrate R.swift into multiple targets where some files are shared between multiple targets. I'm sure it's a common theme for big production apps.

@iadcialim
Copy link

I experienced the same issue, however, I believe that the problem is not really on the R.swift side but rather in your project configuration.
In my case, the project has also a target for MyAppUITests. In your scheme configuration that builds MyAppDev target (Edit scheme -> Build), you'll have most likely also the MyAppUITests target. If your MyAppUITests target has a MyApp dependency then you're building both targets in one step which results in generating twice the R.generated.swift and results in this error.

@branohricardo I have this issue now with my unit test. How to proceed with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants