Conversion to Swift 5 produces 'Multiple commands produce x86_64.swiftmodule' error - swift5

I am trying to get Xcode 10.2 to convert my hybrid Objective-C / Swift project to use Swift 5. Whenever I do this, however, the compilation files due to the following error
error: Multiple commands produce '/Users/<User>/Library/Developer/Xcode/DerivedData/SurgEval-chcbdqcuvbtwckedraqzdhwbsqpm/Build/Intermediates.noindex/SwiftMigration/SurgEval/Products/Debug-iphonesimulator/MYAPP.swiftmodule/x86_64.swiftmodule':
1) Target 'MYAPPTests' (project 'SurgEval'): Ditto /Users/alenox/Library/Developer/Xcode/DerivedData/SurgEval-chcbdqcuvbtwckedraqzdhwbsqpm/Build/Intermediates.noindex/SwiftMigration/SurgEval/Products/Debug-iphonesimulator/MYAPP.swiftmodule/x86_64.swiftmodule /Users/<User>/Library/Developer/Xcode/DerivedData/SurgEval-chcbdqcuvbtwckedraqzdhwbsqpm/Build/Intermediates.noindex/SwiftMigration/SurgEval/Intermediates.noindex/SurgEval.build/Debug-iphonesimulator/MYAPPTests.build/Objects-normal/x86_64/MYAPP.swiftmodule
2) Target 'SurgEval' (project 'SurgEval'): Ditto /Users/<User>/Library/Developer/Xcode/DerivedData/SurgEval-chcbdqcuvbtwckedraqzdhwbsqpm/Build/Intermediates.noindex/SwiftMigration/SurgEval/Products/Debug-iphonesimulator/MYAPPL.swiftmodule/x86_64.swiftmodule /Users/<User>/Library/Developer/Xcode/DerivedData/SurgEval-chcbdqcuvbtwckedraqzdhwbsqpm/Build/Intermediates.noindex/SwiftMigration/SurgEval/Intermediates.noindex/SurgEval.build/Debug-iphonesimulator/SurgEval.build/Objects-normal/x86_64/MYAPP.swiftmodule
I have already tried switching to using the 'Legacy Build System' as suggested in other similar questions, but I would like to migrate to the new build system.
I have also tried to change the product module name in my test target as suggested in another question, but that broke my tests.
The application and tests both build and run fine otherwise, I just get a compilation error while running the Swift 5 migration tool.
Any idea what's going on here, or some some docs I can look at to better understand this?
Thanks!

I was able to partly solve this issue by adjusting SWIFT_MODULE_NAME property in Test target.
My test's target SWIFT_MODULE_NAME was same as main target name, so i changed it

Related

error: could not build Objective-C module 'Quick'

Running my Quick and Nimble tests in Xcode and I am now getting this error out of the blue.
Build/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Quick.build/module.modulemap:2:19: error: umbrella header 'Quick-umbrella.h' not found
umbrella header "Quick-umbrella.h"
^
error: could not build Objective-C module 'Quick'
How can I fix this?
Quit Xcode
Clear your derived data. You can find your derived data in here
~/Library/Developer/Xcode/DerivedData
Clean your project (⌘+Shift+K)
Build your project (⌘+B)
Or ;
Another way can fix your issue :
Go to Xcode Preferences
Choose Test
Check the Gather coverage tick as indicated the ss :
Issue seemed to be the fact that my M1 doesn't support iOS versions lower than 14. I did not have the correct one selected without realizing and I spent a lot of time trying to figure out why Quick testing wasn't working but my XCTests were.

Swift 4 migration

Good morning,
I have Xcode 10.1 and Swift 3.2
I am trying to migrate to Swift 4.0, but unfortunately I have got these errors:
A. Multiple commands produce '/Users..../path/'
1. Target "ApplicationTests"
2. Target "ApplicationUITests"
3. Target "Application"
B. Cycle in dependencies between targets "ApplicationTests" and "Application"; building could produce unreliable results.
Cycle path: Application Tests -> Application -> Application Tests
Target build order preserved because "Parallelize Build" is off.
Maybe someone knowns how to fix it.
Thanks!
If your app really doesn't have that cycle stated, you might want to clean and rebuild your app. Clean by pressing Cmd + Option + Shift + k and then rebuild/rerun your application. That usually solves some build problems in Xcode.
Edit
Also, you might want to check your Build System to use the new or legacy one. Go to File -> Project Settings (or Workspace Settings) and configure it properly. Try using legacy build system; New build system still presents odd behavior sometimes.

"Copy swift standard libraries" build step does not include SwiftOnoneSupport.dylib

I have been experiencing a troubling problem lately that has to do with the running of tests on a project which has a cocoapods dependency to a framework which crashed at runtime with error:
Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: MyCocoapodsDependency
There are other stackoverflow topics out there about that particular problem but none of them address root cause (for example here), which is that during the "Copy swift standard libraries" step of the test build, the missing library is not copied over.
It looks like this (this is the build log when I build the tests):
When it should look like this (this is the build log for a test app that uses the exact same dependencies):
OnOneSupport seems to have to do with with a project setting that has to do with "Whole module optimization".
But even if I change to "not onOne" it doesn't make a difference. The dylib is referred to in https://github.com/apple/swift/blob/master/cmake/modules/AddSwift.cmake
I cannot for the life of me figure out why it's omitted from the standard libraries build step for one target and not for another, but its obvious that my tests needs it. Anybody know how I can force the compiler to include SwiftOnoneSupport?
Workaround
Add a build phase to the test target (in the project file) that copies libswiftSwiftOnoneSupport.dylib to Frameworks. The dylib can be found at:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bitcode_strip /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/libswiftSwiftOnoneSupport.dylib
I also had this same issue with two of my frameworks. The strangest thing was that everything was working fine with one of them but not with the other.
While I wasn't able to figure out why this happens (since it seems to be an Xcode bug), I was able to find a pretty neat workaround.
Turns out that using print() anywhere in your code will somehow force libswiftSwiftOnoneSupport.dylib to be loaded. So, by adding something like this the problem should go away:
private func dummy() {
print("Hello world!")
}
I'm using Xcode 10.1, Swift 4.2 and the pod that was giving me this issue was Nimble.
Hope this helps!

Build operation failed without specifying any errors when adding Swift Unit tests to projects

I'm currently working on an objective c project where we are trying to now incorporate swift into the project. When I add a Swift unit test to the project I get the following prompt:
I create the bridging header. However, when I try to run my tests I keep getting the following error:
Build operation failed without specifying any errors. Individual build
tasks may have failed for unknown reasons. One possible cause is if
there are too many (possibly zombie) processes; in this case,
rebooting may fix the problem. Some individual build task failures (up
to 12) may be listed below.
I've googled for the error and most people say restart the simulator, xcode, your machine etc. I've done all of this. The problem seems to lie in using swift inside of my unit tests.
Any ideas?
Try moving your project closer to your root directory. Swift compiler can have issues with reaching ARG_MAX in large projects.
https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494

Getting dyld_fatal_error after updating to Xcode 6 beta 4 using swift

I just recently downloaded Xcode 6 beta 4, and my swift project compiles with no errors but before it gets to my code I get a dyld_fatal_error just above start in the call stack.
and a breakpoint in some assembly code with a nop instruction
The console error I get is
dyld: lazy symbol binding failed: Symbol not found: __TFSsa6C_ARGVGVSs13UnsafePointerGS_VSs4Int8__
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/Sudoku
Expected in: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/../Frameworks/libswift_stdlib_core.dylib
dyld: Symbol not found: __TFSsa6C_ARGVGVSs13UnsafePointerGS_VSs4Int8__
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/Sudoku
Expected in: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/../Frameworks/libswift_stdlib_core.dylib
Just so you know the project still compiles, and runs fine with Xcode 6 beta 3.
Most extremely weird problems like this can be solved with a Clean & Build (or perhaps relaunch Xcode). You might also consider deleting the relevant folders from ~/Library/Developer/Xcode/DerivedData.
For sure this error is very unhelpful:
dyld`dyld_fatal_error:
-> 0x1200ad088 <+0>: brk #0x3
This of course occurs only on device, not the simulator. Another good reason to always test on a device.
Anyway, having had the same issue, a clean didn't work for me. Deleting DerivedData didn't help either. Also tried synchronising the Deployment Target versions. That didn't seem make any difference but I did it anyway.
Solution was to add any dynamic frameworks to Embedded Binaries setting under Target -> General:
Now I know that has been mentioned in other answers. However, if I can supplement by saying that any dependent dynamic frameworks must also be included.
So for example if you have a dynamic framework A that depends upon dynamic framework B, then it's necessary to have A and B added to Embedded Binaries.
Note that if the dynamic framework A depends upon any static library or framework, you will almost certainly be forced to create A as an umbrella framework that includes the dependant binaries.
Other considerations that may or may not be important. However did personally for me result in success were;
paths of each dynamic library in the Inspector were set to "Relative
to Group". In the screen grab above the path of the embedded binary
appears correct terminating with "build/Debug-iphoneos".
dynamic frameworks are in embedded binaries section. Static libs and
static libs wrapped up as frameworks are in Linked Frameworks
and Libraries. Nothing appears in both sections.
In setting this up XCode behaved strangely. The following proved successful:
Add the dynamic framework to the embedded binaries.
Find the new framework in XCode groups on the left and update the path to be
"Relative to Group" as described previously.
Delete the dynamic framework from embedded binaries.
Add the dynamic framework to the embedded binaries again. The path should now appear correctly.
Delete all references to the dynamic framework from the Linked Frameworks
and Libraries section.
I have just had this problem trying to link a custom iOS framework to my project, so for anyone out there who has this problem, it's to do with the copy files build phase.
I think that this error results when a file cannot be found. So create a copy files build phase in the appropriate target in your project. Then add the file (in my case the custom framework) to this phase (if it's a framework make sure to select the 'Frameworks' destination).
Cleaning, restarting, deleting etc didn't work for me.
I have a project containing another project. When I ran the project on iOS 7 and the contained project was accessed in code, the app stopped at the line below:
After many days, I saw that the deployment target for the container project was 7.0 (as can be seen below).
The contained project on the other hand, had a deployment target of 8.1 (as can be seen below).
Changing the deployment target of the contained project to 7.0 solved my problem!
The project was working fine on iOS 8 devices.
I had this issue recently and the problem for me was that I had added a library from the same project which wasn't listed in 'Embedded Binaries' from the 'General' section.
NOTE: If you add it in Embedded Binaries it will also add to the Linked Libraries section, possibly adding the same one twice.
Clean and build won't work. You'll need to delete he cache in ~/Library/Caches/com.apple.dt.Xcode* directories. Delete these and rebuild.
Do this every time you upgrade the beta.
I also faced the same issue and tried all the solution given above without any luck.
then what I have done to resolve that I really don’t have much I idea about. So there is Certificated called “apple worldwide developer relations certificate authority” in System group in keychain Access and due to some profile and certificate issue I randomly mark this certificate “Always trusted” from “Use System Defaults”. So this is causing this “dyld_fatal_error” crash to me. when I revert it back to “Use System Defaults” crash got resolved.
So guys if you are tried all the possible option to resolve this crash and didn’t succeed yet, try this also. It helped me, may help you as well.
Found this about this certificate.
This problem still occurs in Xcode 7, and it can happen for a variety of reasons (it seems). In my case, the iOS app with an included framework:
ran on the simulator fine
gave the error you described on the device
The answer was to NOT use linked libraries but rather Embedded Binaries under General.
Also see here: https://stackoverflow.com/a/34052368/8047
Adding the non-system Framework to "Embedded Binaries" inside the general tab of the main project worked for me.
As stated by bitwit, this will also add your framework to "Linked Frameworks and Libraries", so watch out for those duplicates.
Tested with Xcode 7.3.
Xcode 8.
Clean and build didn't work. I deleted the cache, deleted Derived data. After that, my pods configuration was broken, so i needed to install pods again. Pods Target configuration was set to a very old Valid architectures. setting to armv7 and armv7s, was ok to compile and no problems
You'll get this if your scheme has "Guard Edges" enabled in diagnostics when running on an actual device. "Guard Edges" only works in the simulator.
I was using cocoapods and had this problem as well when I updated to deploy target iOS 8 and added use_frameworks! to my Podfile. I was able to fix it by adding the following line to my Podfile:
link_with 'TargetName1', 'TargetName2', etc.
Might work with ProjectName as well