Build fails with "Command failed with a nonzero exit code"

Xcode

Xcode Problem Overview


When I try to build my app with Xcode, an error interrupts the build process:

> Command CompileStoryboard failed with a nonzero exit code

Sometimes, it shows this error instead:

> Command CompileSwift failed with a nonzero exit code

I have New Build System turned on.

What can I do to fix this?

Xcode Solutions


Solution 1 - Xcode

Closing Xcode for me didn't have an effect. Instead, I cleaned the project using CommandShiftK.


I also found another reason: I had a storyboard reference to another storyboard which I had removed. The quick fix was deleting this.

enter image description here

Solution 2 - Xcode

When you stop building a project when the compiler is in the middle of something "important", this error could appear. In that case, building the project again and letting it finish normally makes this error disappear.

Solution 3 - Xcode

I also facing same issue in xcode 10 and tried all the solutions provided but nothing working.

Then I deleted all the files and folders of the following folder :

~/Library/Developer/Xcode/DerivedData

and it worked like a charm.

Solution 4 - Xcode

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 methods suggested here (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 5 - Xcode

I encountered this error when I was upgrading my project from Swift 4 to 5. I first updated all my pods to their latest versions. When I built, some pods showed this error.

The following steps resolved this issue for me:

  1. Removed all pods from Podfile
  2. Executed pod install to remove all installed pods
  3. Executed pod deintegrate to remove support for CocoaPods
  4. Deleted Podfile.lock and .xcworkspace from my project so no CocoaPods anymore
  5. Now my project is a pure Xcode project
  6. Opened my project from the regular .xcodeproj file
  7. Changed Swift Version of my project to Swift 5
  8. Cleaned the project (cmd+shift+K)
  9. Quitted Xcode
  10. Restored all pods to my Podfile
  11. Executed pod install to reintegrate CocoaPods and add my pods
  12. Opened the project from the .xcworkspace file
  13. Cleaned and rebuilt
  14. Some old pods that were still using Swift 4.0 (SlideMenuControllerSwift in my case) were set to Swift 5.0, caused many build errors in their code. I corrected it back to Swift 4.0 by opening the Pods project and selecting its target.
  15. Cleaned again, rebuilt.

Now I have only errors in my own project code related with difference in Swift version I made. My job now is to fix them.

Solution 6 - Xcode

This error happened to me when I forgot to change entity Properties before creating NSManagedObject subclass. Solved by:

  1. delete Entity+CoreDataClass.swift and Entity+CoreDataProperties.swift.
  2. under "class" of the entity model inspector, change "module" to Current Product Module and "codegen" to Manual/None.
  3. recreate the NSManagedObject.

image

Solution 7 - Xcode

I had the error Command LinkStoryboards failed with a nonzero exit code, and found that I was using a reference to a non-existent storyboard. I had recently changed the name of a storyboard file, so changing the reference from the 'old' name to the 'new' name solved it for me.
You may not have exactly the same error as me, but an easy way to find a more detailed explanation of the error is to:

  • Show the issue navigator (while the build time error is showing)
  • Click the error: Click the error in the issue navigator
  • Then, you should see more about your error: Command LinkStoryboards failed with nonzero exit code


I hope this helps. Please, I am aware that I am answering from experience of a different error than this question was asked about, but I believe this advice should help you conquer similar problems!

Solution 8 - Xcode

If you have multiple targets, where two or more targets have files with the same name, check the target membership of those files in Files inspector. The error occurs when multiple instances of the equally named file have set the target membership for the same target.

Solution 9 - Xcode

For me cleaning the project (Command + Shift + K) and restarting xCode worked for me

Solution 10 - Xcode

Since this issue looks to have dozens of possible solutions and the root cause could be very vague, I'll throw my situation into the ring. Half of my pods were failing with some sort of CompileSwiftSource failure, but only on archive. I was still able to build for device and simulator just fine. I tried a lot (if not all) of the solutions suggested here with no luck. One of the pods had a slightly different error before the CompileSwiftSource error so I went to updating and trying to fix that single pod. It was the Cache library for iOS which hadn't been updated in a while. There was a fork that resolved the issue with updating to Xcode 10.2 that I was able to update to and after that, all of the other issues took care of themselves. So look for a single outlier in your pods if you're getting a bunch of them erroring out and start there.

Solution 11 - Xcode

Switching to the legacy build system fixed the issue for me

Solution 12 - Xcode

I had the JSONwebtoken pod installed and that was causing issues. I needed to delete the CommonCrypto folder that is in the JSONWebtoken pod folder. Here is a ->link<- explaining the issue. This started happening in Xcode 10.

Solution 13 - Xcode

In my case, I was clean build folder then restart my mac then it's work.

Solution 14 - Xcode

In my case it was about having a file named Location. after some digging I find out that it was about having two file with the same name (weird). Cause I don't, however, it's been solved by removing the file and adding another file with a different name.

filenames are used to distinguish private declarations with the same name

Solution 15 - Xcode

This can also occur when you have two swift files with the same name. For example, two ContentView.swift files

Solution 16 - Xcode

In my case, I used too complicated initializations inside a class extension. It suddenly broke my build.

class MyClass { }
extension MyClass {
static var  var1 = "", var2 = "", var3 = "", var4 = "", ...., var20 = ""
}

Resolved:

class MyClass { }
    extension MyClass {
    static var var1 = "",
    static var var2 = "",
    static var var3 = ""
    static var var4 = "", ...., 
    static var var20 = ""
    }

Solution 17 - Xcode

In my case it was empty assets catalog, when I delete it everything was fine again.

Solution 18 - Xcode

Command CompileSwift failed with a nonzero exit code

This error happens when you are migrating your code from Xcode 9 to Xcode 10+. It due to any class name is conflicting with existing apple classes. For Example: State, Event etc.

  1. So first change the class/structure name if any existing in your code like "State" to "StateDetail"

  2. If Info.plist is added in target, remove tick mark from it so it will not copy app bundle (Latest Xcode10 security reason).

  • Select Info.plist file and uncheck under "Target Membership" in right side Identity inspector

And build code again!!!

Solution 19 - Xcode

In my case, the problem was that I assigned a .swift class to the viewController in the storyboard, while the project was Objective C.

Solution 20 - Xcode

I got this error while trying to run my unit tests in a submodule. What I have done is:

Change the simulator => Clean the project => Build the project => Run unit tests.

After this, my unit tests ran without any issue.

Solution 21 - Xcode

I tried a lot of the options discussed here.

  • Delete and reinstall pods
  • Clean Build Folder
  • Delete Derived Data
  • Add SWIFT_ENABLE_BATCH_MODE and set its value to NO
  • Restarting Xcode and Recompiling
  • Restarting iMac and Recompiling
  • set Compilation Mode to Incremental
  • Changed build settings: SWIFT_COMPILATION_MODE = singlefile and SWIFT_OPTIMIZATION_LEVEL = "-O"

Nothing worked. I'm using Xcode Version 11.0 beta (11M336w).

Finally I downloaded a fresh copy and replaced the one I had previously installed. It was the same exact version. That did the trick.

Solution 22 - Xcode

I have the issue like that and my solution is change a little thing in Build Settings:

SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OPTIMIZATION_LEVEL = "-O";

it work to me

Solution 23 - Xcode

Alright, I was having the same problem with Xcode 10. I usually use a storyboard for every view, that way if someone is helping it's easier to fold code in. I needed to make one of the view on one storyboard the initial view Controller.

Solution 24 - Xcode

In my case it was renaming a file to an existing file in other folder(Group) by mistake, just rename it to what it was then the error disappeared

Solution 25 - Xcode

The targets should be specified with related data such as appicon

Solution 26 - Xcode

For me the problem was that on my Podfile I didn't put use_frameworks!. I just uncomment that line, run pod install on the terminal again. And it got fixed.

It was commented since the app was entirely made on Objective-C. Since the app now uses Swift I had to make that change on the Podfile

Solution 27 - Xcode

I had the same error Restarting Xcode and Recompiling Fixed the issue for me.

Solution 28 - Xcode

I got the same error when linking separate storyboards. The error, "Command CompileSwiftSources failed with a nonzero exit code." is shown because I simply forgot to set the view controller inside the second storyboard that I am linking as 'an initial view controller'.

Solution 29 - Xcode

In my use case I had used the function "Refactor to Storyboard" in Xcode 13. It created the new refactored story board fine but failed to add it to bundle resources.

So my fix was to:

  • Select the target project in Xcode Navigator
  • Choose the build phases tab
  • Expand Copy Bundled Resources to see if new storyboard was added. If not, just add it to the list and rebuild.

Solution 30 - Xcode

My app was having Notification Service Extension, and was using Xcode 11. The Extension doesn't have anything to do with pods.

After 1-2 years, I have taken that project into my new m1 chip mac with Xcode 13. But the compilation was failing and showing me the error in pods.

I tried to remove and add all pods, tried clean etc all possible available answers available on internet. Almost spent 4-5 hours to make it run, but nothing worked.

Final Solution that worked:

I removed, notification service extension from the project, its target etc too. And then tried to run the app. Amazingly it worked. After that, i added that extension again(by creating new extension and putting the same code again), and everything is working perfectly fine.

I am still surprised that, was that issue with extension or with pods. But finally it worked for me.

Hopefully, this answer might resolve someone's issue and you can save enough time.

Solution 31 - Xcode

I've seen this error on an enterprise account when user account permissions were changed and new profiles were generated.

In my case I fixed it by revoking my developer certificates and letting xcode regenerate them.

The brute force way to do this is log out of your account in Xcode, then open Keychain Access, export your developer certs and private keys (i.e. make a backup just in case). Delete the certificates and private keys from Keychain Access (you did that backup step, right?), reboot, open xcode and login to your account again and then choose "manage certificate" ... it should prompt to regenerate certificates.

After that this random build error went away.

Solution 32 - Xcode

What helped to me is to set Compilation Mode to Incremental for all configurations in Target's Build Settings. With Whole module compilation mode I got errors. But this setting made project build slower.

Solution 33 - Xcode

If you are facing an error like that on new MacOS version.

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

It means that you need to install XCode command line, open a Terminal and run this command:

$ xcode-select --install

Solution 34 - Xcode

What was causing these errors for me (I was getting 8+ for some of my cocoapods) was fixing any runtime build issues in all the pods.

Solution 35 - Xcode

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

Solution 36 - Xcode

I have faced similar problem. I have done

  • clean project - didn't work
  • Remove Derived Data Folder - didn't work
  • Change build system to Legacy Build Settings - didn't work
  • Restart XCode - didn't work
  • Comment some of my code, a typedef NS_ENUM in .h file and enums related works. Build the system and build success shown. Next un-comment the code and build again - Magically works

Solution 37 - Xcode

Context: I was having a similar issue "Command CompileStoryboard failed with a nonzero exit code" after trying to build an iOS flutter app with the latest and Android studio and XCode 11.3 (new installation on Mojave). This was an existing flutter android app I had built with Android studio on Windows 10.

Tried and failed: Command+Shift+K, Command+B, Delete Derived data, SWIFT_ENABLE_BATCH_MODE = NO

Solution:

  • Open Finder and Navigate to project name > ios > Runner > Base.Iproj
  • Delete .storyboard files (main and launch)
  • Open terminal and run "flutter create ."
  • Open Xcode and run

Solution 38 - Xcode

If you are using a TabbController and a storyboard references, make sure that you have a starting point for that storyboard.

Solution 39 - Xcode

For me this was to do with a constraint that I was removing at build time. Unticking Remove at build time fixed the issue, and I suspect the compiler had an issue determining the layout without it.

The error code will mention which Storyboard is causing the issue.

Solution 40 - Xcode

What we do, we just clean the project. Only cleaning the project sometimes doesn't work. After deleting the Build Folder, XCode starts indexing. Let think XCode as human :D and let it index for some time. The error will completely vanish.

Solution 41 - Xcode

I had files with the same name in different folders which caused this error.

Solution 42 - Xcode

I have run on this error

Command CompileSwift failed with a nonzero exit code

when tried to build application(consumer) with breaking framework(producer)

If you double click on this message you see all green checks. To figure out what happened

Report Navigator -> <project_name> -> Build 

Solution 43 - Xcode

it's simple you forgot to on is Initial view controller in the second storyboard that's it.

see in the image... is Initial view controller

Solution 44 - Xcode

Read various article and tried many things. An easy procedure that worked in my case:

  • removed Pods folder
  • pod install
  • product, clean build folder
  • product, build

Solution 45 - Xcode

If you are using CocoaPods, make sure you opened the Xcode workspace and not the project.

Solution 46 - Xcode

In my case, a message appeared as follow.

> Command CompileSwiftSources failed with a nonzero exit code.

I changed toolchain Xcode->Toolchain->Xcode 10.1

This was happened right after I update to Xcode10.1. I hope it will work.

I also attach a link more about manage toolchain.

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
QuestionTam&#225;s SengelView Question on Stackoverflow
Solution 1 - XcodeGeorgeView Answer on Stackoverflow
Solution 2 - XcodeTamás SengelView Answer on Stackoverflow
Solution 3 - XcodeKrishna MeenaView Answer on Stackoverflow
Solution 4 - XcodecdeerinckView Answer on Stackoverflow
Solution 5 - XcodeMostafa Al BelliehyView Answer on Stackoverflow
Solution 6 - XcodeJeffreyWang23View Answer on Stackoverflow
Solution 7 - XcodeBenjView Answer on Stackoverflow
Solution 8 - XcodeAdam BardonView Answer on Stackoverflow
Solution 9 - XcodeMoamen MostafaView Answer on Stackoverflow
Solution 10 - XcodeSteve EView Answer on Stackoverflow
Solution 11 - XcodeCharlton ProvatasView Answer on Stackoverflow
Solution 12 - XcodeK-2SOView Answer on Stackoverflow
Solution 13 - XcodeMd. IbrahimView Answer on Stackoverflow
Solution 14 - XcodeSinaMN75View Answer on Stackoverflow
Solution 15 - Xcodeuser15192869View Answer on Stackoverflow
Solution 16 - XcodeVyacheslavView Answer on Stackoverflow
Solution 17 - XcodeYaroslav SarnitskiyView Answer on Stackoverflow
Solution 18 - XcodeSandip Patel - SMView Answer on Stackoverflow
Solution 19 - XcodemahdiView Answer on Stackoverflow
Solution 20 - XcodeUdaya SriView Answer on Stackoverflow
Solution 21 - XcodeGIJoeCodesView Answer on Stackoverflow
Solution 22 - XcodeDaniel LeView Answer on Stackoverflow
Solution 23 - XcodejimistephenView Answer on Stackoverflow
Solution 24 - XcodeAmir MehrnamView Answer on Stackoverflow
Solution 25 - Xcodeuser10375102View Answer on Stackoverflow
Solution 26 - XcodeLuis FelipeView Answer on Stackoverflow
Solution 27 - XcodeAbdulmoiz AhmerView Answer on Stackoverflow
Solution 28 - Xcodeuser11737584View Answer on Stackoverflow
Solution 29 - XcodeAndrew ThompsonView Answer on Stackoverflow
Solution 30 - XcodeMehul ThakkarView Answer on Stackoverflow
Solution 31 - XcodeparView Answer on Stackoverflow
Solution 32 - XcodeDenis KutlubaevView Answer on Stackoverflow
Solution 33 - XcodeAsif voraView Answer on Stackoverflow
Solution 34 - XcodeKevin RView Answer on Stackoverflow
Solution 35 - XcodeHenriqueVellosoView Answer on Stackoverflow
Solution 36 - XcodeAnkur LahiryView Answer on Stackoverflow
Solution 37 - XcodedevknightView Answer on Stackoverflow
Solution 38 - XcodehemingView Answer on Stackoverflow
Solution 39 - XcodeCristianMoiseiView Answer on Stackoverflow
Solution 40 - XcodeAnkur LahiryView Answer on Stackoverflow
Solution 41 - XcodecoraView Answer on Stackoverflow
Solution 42 - XcodeyoAlex5View Answer on Stackoverflow
Solution 43 - XcodeChandanView Answer on Stackoverflow
Solution 44 - XcodeLMGView Answer on Stackoverflow
Solution 45 - XcodeRic SantosView Answer on Stackoverflow
Solution 46 - XcodeTonghun HwangView Answer on Stackoverflow