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.
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 :)
@RodrigoLGuimaraes For me, using the Legacy Build System works, the bug is only with New Build System.
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.
For me, I have R.swift build phase in 2 targets. Removing it in 1 works for me
@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.swiftB) 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.swiftUpon changing, I had to rebuild the project in each target, add the newly generated
R.staging.generated.swiftto the project in the staging target and change the oldR.generated.swiftto 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 :)
@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 generatedR.staging.generated.swiftto the project in the staging target and change the oldR.generated.swiftto 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.
I experienced the same issue, however, I believe that the problem is not really on the
R.swiftside but rather in your project configuration.
In my case, the project has also a target forMyAppUITests. In your scheme configuration that buildsMyAppDevtarget (Edit scheme -> Build), you'll have most likely also theMyAppUITeststarget. If yourMyAppUITeststarget has aMyAppdependency then you're building both targets in one step which results in generating twice theR.generated.swiftand results in this error.
@branohricardo I have this issue now with my unit test. How to proceed with this?
Most helpful comment
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.swiftB) 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.swiftUpon changing, I had to rebuild the project in each target, add the newly generated
R.staging.generated.swiftto the project in the staging target and change the oldR.generated.swiftto 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 :)