212

After updating to the latest version of Xcode at the moment (version 10.0) the project is unable to build because it found some errors regarding some "Command CompileSwift failed with a nonzero exit code" error.

How do I solve this errors? They appear in most of the Pods (I use CocoaPods) I use inside my project.

I have tried updating the pod version and the pods to the latest version available, but the problem is still there.

I have searched a lot through the web and there is very little information regarding this issue.

17
  • 29
    pod install --repo-update, then in your xCode clean build folder and delete derived data, try build again after that. Commented Sep 18, 2018 at 13:15
  • It didn't work @inokey Commented Sep 18, 2018 at 13:20
  • 1
    Check deployment target in the project settings. Commented Sep 18, 2018 at 13:23
  • The iOS deployment target is set to 9.0, is that a problem? Thanks again @inokey Commented Sep 18, 2018 at 13:26
  • 2
    Another possible solution (that worked for me) is found here: stackoverflow.com/a/52481653/96153 Commented Oct 5, 2018 at 3:06

23 Answers 23

154

For me, just cleaning project works using ShiftCommandK & OptionShiftCommandK.

Sign up to request clarification or add additional context in comments.

9 Comments

This did not solve the issue for me, it did nothing.
@VanDuTran close ur xcode and reopen it
Yup, this worked for me too Xcode 10.2.1, iOS 2.3.1, iPhone XS Max. Thank God it wasn't going to be looking for a needle in a haystack. I didn't change that much between last compile and where I was getting that error.
This answer is the equivalent of IT, telling people to try turning it off and on again. Which of course it solved for me.
Not only did I upvote because this is the correct answer, but good job adding the shortcut buttons for people. Shift + Command + K is my go to "Why is this not compiling?" solution.
|
93

You're most likely not reading the entire error message. If you look above the "Command CompileSwift failed with a nonzero exit code" message you should find some specification like this:

enter image description here

In this example I had two files with the same name. Once I fixed it everything worked as it should.

2 Comments

Hello, @Samy. What did you do exactly?
Well in my example 2 files had the same name so I changed one of them.
54

I attempted

  • Closing & Reopening Xcode
  • Cleaning Build Folder
  • Running pod install --repo-update

and all of these still did not fix the problem.

Restarting the Mac did the trick!

8 Comments

I updated my xcode to 10.3 and faced similar issues. I tried all the tricks nothing helped but as indicated in here in bold, "Restarting the mac did the trick", it worked for me.
Hate to say that but restarting my mac did solve the issue for me. BTW I got this error after upgrading Xcode to 10.3.
Before you try anything "Restart the Mac". This should be top answer.
Clean Build Folder worked perfectly for me (only clean, without restarting the Mac).
The thing with restarting the Mac might look funny, but it's a valid point! In my case I modified the .bash_profile, then quickly in the terminal loaded it: source .bash_profile and proceeded to work. So after few days when I returned back, I had again issues because .bash_profile was not loaded... Then restarting does indeed help :)
|
48

Currently my build is working. Here you are the steps I tried until it finally worked:

  1. Search in the whole project the word CommonCrypto.
  2. If you have a Pod containing that header import, remove this Pod from the Podfile and perform a pod install.
  3. Clean and build the project.
  4. Add again the Pod to the Podfile and perform a pod install.
  5. Clean and build the project again using a real device if possible.

And If you don't have that Pod, maybe you can try by making the same steps with some old Pod that you may encounter in your project.

Added information: also If you have some code error inside a Pod, first you need to solve that code problem and then try to compile again the project.

I'm going to copy the changes made in my project.pbxproj. I know it's not very helpful but it's the only thing that have changed in the git difference commit:

Removed: BDC9821B1E9BD1B600ADE0EF /* (null) in Sources */ = {isa = PBXBuildFile; }; Added: BDC9821B1E9BD1B600ADE0EF /* BuildFile in Sources */ = {isa = PBXBuildFile; }; 

I hope this can help,

Regards.

7 Comments

Didn't work with me , specially when i try to imbed framework I created before.
Do you find any other error? Or only the CompileSwift?
Had this problem with Kingfisher pod, your approach helped, thanks!
Fixing other code issues and then doing those steps solved the problem for me
Why should this work?
|
44

I had this issue and changing the Compilation Mode setting for the project from Incremental to Whole Module fixed it for me.

enter image description here

7 Comments

This helped me fix the problem. When I turned Whole Module mode on it started reporting actual errors to me rather than a generic high level failure. Once all fixed you can then change it back to Incremental, if that's what you'd like.
Any hints where to find this setting? i looked under build settings for my targets and build settings for the project and cant find it (by searching for it) maybe because im on an objective-c project thats quite old?
It's under Swift Compiler -> Code Generation. Alternatively it may sometimes be listed under User Defined -> SWIFT_COMPILATION_MODE
This did not solve the issue for me, it did nothing.
Thanks for the tip and it fixed my problem. My case is to migration project to Xcode 10.2 and Swift 5. I wrote detail explanation about it in my blog: davidchuprogramming.blogspot.com/2019/03/…
|
12

This is a known issue with Swift 4.2 and Xcode 10. I found an article here that fixed it for me: https://github.com/Yummypets/YPImagePicker/issues/236

In short, go to your projects build settings, and add a user defined setting named SWIFT_ENABLE_BATCH_MODE and set its value to NO.

Previously, I tried each of the following methods suggested elsewhere (rebuild, exit Xcode, clean and rebuild, purge Derived Data files). None of them worked.

Once I added the user define build setting per the article, Swift then told me the true error. In my case, it was a missing }, but it could be any number of problems.

4 Comments

This did not solve the issue for me, it did nothing.
However, I get this error message instead: Command PrecompileSwiftBridgingHeader failed with a nonzero exit code
i didn't work, got same error again.
This worked for me; revealed the underlying error.
12

My problem was I had due to the non-existence of a native Swift CommonCrypto, used a bridging header and a target that with some magic included it in the build. Since CommonCrypto is now native, I solved the problem by removing the target and the #import and instead added an import CommonCrypto where I used it.

3 Comments

Yes! I had this too (No cocoapods or anything like that, just CommonCrypto) Thanks for saving my day
@OmidAriyan Hello, guys this issue had stopped me from working for the past two weeks :s, I tried almost all solutions found on this website but its simply not working. For your answer I didn't get the point actually. Would you please clarify your answer for me in details? What is the problem and what should I do in steps please :(:(
@mojtabaalmoussawi I had basically followed stackoverflow.com/a/42852743/1038245 in order to use CommonCrypto in my project before Xcode 10 was released. I just tried to undo that to fix the error that is the topic of this question.
9

I did the following and it works like charm:

  • Open Xcode Preferences (Command,)
  • Go to the Locations tab
  • Click on the small gray arrow which shows URL path for Derived Data
  • The finder window will open up and show the following folders:

    • DerivedData
    • Archives
    • iOS DeviceSupport
    • UserData
    • DocumentationCache
    • iOS Device Logs
  • Quit Xcode

  • Delete the DerivedData folder (it just contains a cache from previous builds)
  • Restart Xcode

3 Comments

This did not solve the issue for me, it did nothing.
Tried many , but this was only solution that worked
great, it works for me with real device, still errors with simulator
7

Here is the solution: - Go to build settings - Search SWIFT_COMPILATION_MODE - If this is "Whole Module" for Release configuration then change it to "Incremental". - Archive now.

When you change the setting to "Incremental" the process succeeds.

Comments

7

Running pod install --repo-update and closing and reopening x-code fixed this issue on all of my pods that had this error.

Comments

5

Mine was a name spacing issue. I had two files with the same name. Just renamed them and it resolved.

Always gotta check the 'stupid me' box first before looking elsewhere. : )

Comments

4

Let me share my experience for this issue fix.

Open target -> Build phases -> Copy Bundle Resources and remove info.plist.

Note: If you're using any extensions, remove the info.plist of that extension from the Targets.

Hope it helps.

1 Comment

This did not solve the issue for me, it did nothing.
4

in my case the problem was due to watchkit extension being set to swift 3 while the main project's target was set to swift 4.2

1 Comment

This right here! This was bugging me for so long! When you are adding frameworks/extensions to your libraries, make sure that both the extension and the library are looking at the same Swift Language Version! Thanks @Itay
3

Class re-declaration will be the problem. check duplicate class and build.

Comments

2

It seems like this is a pretty vague error, so I will share what I did to fix it when I ran into this:

Using Xcode 10.1 and Swift 4.2 I tried pretty much all the suggestions here but none of them worked for me, then I realized a dependency I was using was not compatible with Swift 4.2 and that was causing me to get this error on other pods. So to fix it I just had to force that pod to use Swift 4.0 by putting this at the end of my Podfile:

post_install do |installer| installer.pods_project.targets.each do |target| if ['TKRadarChart'].include? target.name target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.0' end end end end 

1 Comment

I entered 5.0 swift version for all pods
1

I searched the whole web but I couldn't find any solution for this problem. I managed to REMOVE the "Common Crypto" path in the section: IMPORT Paths in Build settings. The problem seems to be that "common crypto" now exists in the foundation in the ios 12 sdk.

So":

Simply remove the path for file "common crypto" in the build settings and the project will build like a charm! :)

2 Comments

Can you clarify where in your build settings that is? Is it a search path?
Yes. Go to Build settings, select "All" Tab instead of "Basics" or "Customized". Now search for : "Swift Compiler - Search Paths" Here if there exists a path for common crypto, remove it.
1

Just adding to this question. My issue didn't have anything to do with CommonCrypto. It created a new Single App application and tested to run. Compiler was complaining about using Swift 4.2

Changing the Swift language to version 4.0 in Build settings fixed the issue. Not sure if this is a bug.

Comments

1

I got this randomly since Xcode 10. I think it occurs when I change something in the code while building starts. The next build works every time.

Comments

1

I also encountered the same issue and I did what @cdeerinck suggested and got to the following link which suggested adding a user-defined variable to the Build Settings to disable batch mode i.e. add a new user defined variable named SWIFT_ENABLE_BATCH_MODE and set it to NO, I was able to get more insights into the issue and I got to know that the error was in a framework using CommonCrypto which was added to it(by me) but since Xcode 10 it is exposed natively as part of Swift (for Apple platforms only), and adding it (or its existence from the previous version) was causing a name collision and hence it was throwing the error. To know more refer to the this link which explains the issue in more detail.

Comments

1

I have the same issue and my solution is change a little thing in Build Settings

SWIFT_COMPILATION_MODE = singlefile; SWIFT_OPTIMIZATION_LEVEL = "-O"; 

Comments

1

In my case, there was a duplicate entry for a framework in the Input Files of Carthage framework section in Build Phases

Comments

1

ERROR = Command CompileSwiftSources failed with a nonzero exit code

In my case When I found this error, I got cramped with compilation. But when I see some related problem answers. I found a duplication file on my project. Where the same viewController was there as a class file. So yeah when I realized it I changed it name to new one. And yeah things changed!!!

Comments

1

For me, the error message said I had too many simulator files open to build Swift. When I quit the simulator and built again, everything worked.

1 Comment

It was similar I was connected to real device disconnected and built worked fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.