Command CompileSwift failed with a nonzero exit code in Xcode 10

IosSwiftXcodeSwift4Xcode10

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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.

Solution 3 - Ios

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.

Solution 4 - Ios

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!

Solution 5 - Ios

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

Solution 6 - Ios

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.

Solution 7 - Ios

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.

Solution 8 - Ios

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

Solution 9 - Ios

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.

Solution 10 - Ios

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

Solution 11 - Ios

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. : )

Solution 12 - Ios

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.

Solution 13 - Ios

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

Solution 14 - Ios

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

Solution 15 - Ios

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

Solution 16 - Ios

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! :)

Solution 17 - Ios

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.

Solution 18 - Ios

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.

Solution 19 - Ios

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.

Solution 20 - Ios

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

SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OPTIMIZATION_LEVEL = "-O";

Solution 21 - Ios

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

Solution 22 - Ios

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!!!

Solution 23 - Ios

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJordi GámezView Question on Stackoverflow
Solution 1 - IosMahgol FaView Answer on Stackoverflow
Solution 2 - IosSamyView Answer on Stackoverflow
Solution 3 - IosJordi GámezView Answer on Stackoverflow
Solution 4 - IoscodeherkView Answer on Stackoverflow
Solution 5 - IosWerner AltewischerView Answer on Stackoverflow
Solution 6 - IoscdeerinckView Answer on Stackoverflow
Solution 7 - IosOmid AriyanView Answer on Stackoverflow
Solution 8 - IosMile DevView Answer on Stackoverflow
Solution 9 - IosAnkit SainiView Answer on Stackoverflow
Solution 10 - IosricksView Answer on Stackoverflow
Solution 11 - IosPruitIgoeView Answer on Stackoverflow
Solution 12 - IosSathish Kumar GurunathanView Answer on Stackoverflow
Solution 13 - IosItay BiancoView Answer on Stackoverflow
Solution 14 - IosRoshan lamichhaneView Answer on Stackoverflow
Solution 15 - IosTyler927View Answer on Stackoverflow
Solution 16 - Iossajede NouriView Answer on Stackoverflow
Solution 17 - IosAlexanderView Answer on Stackoverflow
Solution 18 - IosheyfrankView Answer on Stackoverflow
Solution 19 - IosSudhanshu VohraView Answer on Stackoverflow
Solution 20 - IosDaniel LeView Answer on Stackoverflow
Solution 21 - IosniksView Answer on Stackoverflow
Solution 22 - IosHarsh VyasView Answer on Stackoverflow
Solution 23 - Iosmef27View Answer on Stackoverflow