215

I get this error after adding a Swift class to an old Xcode project.

dyld: Library not loaded: @rpath/libswift_stdlib_core.dylib

How can I make the project run again?

Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93
Anton
  • 5,932
  • 5
  • 36
  • 51
  • You also might want to look at http://stackoverflow.com/questions/38364320 which shows how to debug this using `otool` – Jim Hayes Aug 01 '16 at 04:11
  • 2017 - incredibly, just **restarting Xcode** solved this heinous issue for me. – Fattie Apr 11 '17 at 18:08
  • https://stackoverflow.com/questions/26024100/dyld-library-not-loaded-rpath-libswiftcore-dylib/69939458#69939458 – Naresh Nov 12 '21 at 12:47

36 Answers36

161

For me none of the previous solutions worked. We discovered that there is a flag ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES (in earlier versions: "Embedded Content Contains Swift Code") in the Build Settings that needs to be set to YES. It was NO by default!

EugenSunic
  • 13,162
  • 13
  • 64
  • 86
mukaissi
  • 2,441
  • 1
  • 21
  • 12
  • This fixed it for me as well, i switched the setting for the extension to true. The project is objc but the ext is swift and didn't worked right from the begining – Cristi Băluță Sep 12 '14 at 08:31
  • This was my resolution as well. I have an existing iOS app project (ObjC) to which I'm adding a Today Extension (new target in the project, extension is a plugin for the main app). I had to go into the app target settings and enable that Build Setting and viola... problem went away. Makes sense, but given how much other stuff Xcode 6.0 automagically configures for you, it's a shame this essential option was overlooked. – hsoi Sep 16 '14 at 11:10
  • This fixed my issue - we had an older project with lots of ObjC, that we recently started adding Swift to. Even though the IPA was built and included the Swift libraries, it did not work on some iOS7 devices until this build setting was checked and we did a new IPA. This worked across all of our troubled devices. – Kendall Helmstetter Gelner Sep 17 '14 at 21:18
  • This worked for me. My framework was a swift one and i needed to change this setting in my swift framework. – bandejapaisa Sep 30 '14 at 11:24
  • 1
    Nothing worked besides this. You are a freakin wizard my good sir! – Ricky Hartmann May 01 '15 at 00:22
  • This should be the correct answer, simple, precise, effective – Tancrede Chazallet May 27 '15 at 15:55
  • Thank you. This is the only thing that worked for me. I tried everything out there: "@executable_path", revoking certs, etc'. – guya Jul 04 '15 at 21:41
  • This did not work for me..I believe it only works when an ObjC project has an embedded Swift framework. – Jeremy Kahn Sep 28 '15 at 22:20
  • This did not work for me when adding a pure Swift framework to a pure Swift project. – Rob Smallshire Mar 02 '16 at 11:17
  • Thank you very much! I was facing dyld: Library not loaded: Alamofire. I was trying to integrate Alamofire.framework using Carthage into an older project written in Objective C. – doruvil Mar 23 '16 at 10:09
  • Two years later and this solution saved my watch project :) Thank you! – Yonatan Vainer Oct 15 '16 at 21:00
  • 2
    Embedded Content Contains Swift Code deprecated use ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES – nivritgupta Dec 02 '16 at 14:18
  • I tried all the solution available on stack overflow, but nothing helps can anyone helps – Gunjan Dave Nov 15 '18 at 11:16
93

This error can occur if something went wrong during the conversion of an Objective-C project to start using Swift. The issue is that the Linker build settings never got configured properly, so you'll have to do it by hand. Look for the Runpath Search Paths build setting and set it to:

$(inherited) @executable_path/Frameworks

enter image description here

EDIT: I should also add that there has been recent spate of these errors caused by something else entirely - Apple made a change in Swift itself, starting in perhaps Xcode 6.1 or 6.1.1. The only solution seems to be to quit Xcode, destroy your certificates in Keychain Access, go to the Member Center and delete all certificates and profiles (except the profiles for apps in the Store - you can't delete them), and then start the entire certificate request process from scratch.

matt
  • 515,959
  • 87
  • 875
  • 1,141
79

I'm not really sure why this question is being downvoted, I had this problem as well when I first tried to use Swift with an existing project. An Xcode restart also fixed this for me.

Adam Fox
  • 3,438
  • 5
  • 23
  • 20
57

I searched long on this issue. There are several reasons causes this issue.

If you are facing when you and Swift code/library in an Objectice C project you should try Solution 1-2-3

If you are facing this issue with a new a Swift project Solution 4 will fit you best.

Solution 1:

Restart Xcode, then computer and iPhone

Solution 2:

Go to project build settings and set Always Embed Swift Standard Libraries (previously Embedded Content Contains Swift Code) flag to YES

Solution 3:

Go to project build settings and add @executable_path/Frameworks to Runpath Search Paths option

Solution 4:

If none of above works, this should. Apple seems to be ninja patched certificates as mentioned in AirSign's post

At InHouse certificates

Subject: UID=269J2W3P2L, CN=iPhone Distribution: Company Name, O=Company Name, C=FR

they added a new field named OU

Subject: UID=269J2W3P2L, CN=iPhone Distribution: Company Name, OU=269J2W3P2L, O=Company Name, C=FR

so you should just recreate certificate and provision

Alistra
  • 5,177
  • 2
  • 30
  • 42
qwerty
  • 2,065
  • 2
  • 28
  • 39
  • 1
    Ad 2: It's now called "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES" (see comment below accepted answer). – Raphael Feb 16 '17 at 08:27
  • 1
    I wanted to add... macOS projects require `@executable_path/../Frameworks` where iOS projects require it without the `..` in the middle. Changing this value is important if you've converted a target from one OS to the other. – Matt Gallagher Apr 29 '18 at 10:50
  • 1
    For me, it wouldn't work without "Solution 3". I was getting the crash running on 10.3.X but not on 10.5.X (both compiled with Xcode 12-beta). The reason was now the Swift libraries are included in the OS so they don't need to be embedded with the binary. But to run on earlier OSs, you need to embed the Swift libs ("Solution 2") and _also_ have the @rpath set to @executable_path/../Frameworks for macOS. When examining the package contents of my app, I saw the libswiftcore libraries were there (ie. embedded), but the app didn't know where to find them at runtime without the rpath set. – Ben Stahl Aug 06 '20 at 01:02
  • @accfews I tried all 3 solutions but facing issue stll – Sanoj Kashyap Oct 07 '22 at 06:36
42

In my case I was trying to import a custom framework and was getting the similar error. Turns out I had to import the framework in the Embedded Binaries rather than in to the Linked Frameworks and Libraries.

Embedded Binaries are under Projects Settings -> -> General

C0D3
  • 6,440
  • 8
  • 43
  • 67
  • 1
    I was seeing this error, when trying to use a compiled framework written in swift (instead of embedding the source files as separate target). Above solution worked for me as well. – alex da franca Feb 13 '15 at 09:59
  • 1
    Worked for me after trying to link a framework partially written in swift into an old project which was entirely objective-c. The setting was actually under build settings though. More information here: http://stackoverflow.com/questions/24163870/what-does-the-embedded-content-contains-swift-code-build-setting-in-xcode-6-do – Pellet Jul 07 '15 at 10:40
  • This is under Target settings, not project, just to be sure. – Legoless Aug 21 '15 at 13:11
  • I'm getting this problem with RestKit when running UITest on a project based on Cocoa pods. Does this mean I should remove the RestKit pod and add directly the .framework? (here my question [http://stackoverflow.com/questions/33997979/ios-app-failing-when-running-ui-test-in-xcode-7-1-1/34040336#34040336] – Claus Dec 02 '15 at 14:00
  • No, if your pods are working, you don't need to add it as a framework to the project. You do have to import the framework at the top of your swift code though. – C0D3 Dec 02 '15 at 15:28
  • That is the only answer that worked for me (twice now). Thanks ! – Arnaud Nelissen Jul 29 '16 at 20:47
  • Thanks, this resolved it for me, where the other higher-upvoted answers did not. – Chris Conway Oct 15 '17 at 22:13
16

For developers who have had this issue with a Adhoc/Enterprise distribution builds,

Create the production certificate from dev portal and then regenerate the distribution profile. Download and install both of them on your Mac. Ensure you selected the right profile in your Xcode build settings and rebuild your app.

Source: https://devforums.apple.com/message/1022908#1022908

orta
  • 4,225
  • 1
  • 26
  • 34
easthelper
  • 161
  • 2
  • 5
16

Solution 5:

In my case, all solutions mentioned in the answer of accfews were very helpful but none has worked. I solved my problem by adding my swift library in the section "Embedded Binaries" in the "General" section of my Project's target. Perhaps is this due to the fact that I have included my swift framework in my workspace? Whatever it compiles now! Get ready Swift, I'm here!

skywinder
  • 21,291
  • 15
  • 93
  • 123
Chrstpsln
  • 765
  • 16
  • 31
  • OK, that seemed to work. I'm just trying to write a swift code library for a swift project. Somehow I still wonder if this is correct. However I'm thrilled its working. – kpierce8 Dec 11 '14 at 06:02
  • I had included my frameworks in the "Copy Frameworks" section of the Build Phases tab - but one framework could not be selected here. The "General" allowed selection of this other framework and added it into the Build Phases, and the app builds and runs. Oddly, I could still run the app on the simulator. – djbp Nov 09 '15 at 15:39
  • Thanks Christophe. Like you, have tried all solutions, and it was clearly not intuitive to understand that a swift library cannot be dragged to a project to another simply. You clearly need to put the library into the embedded section (aka more clearly swift module, I doubt there can be other type of embedded stuff). Even if Xcode could nicely detect it automatically and do the job for us... But that's not the task of our beloved XCode ;), definitively here to waste our time ... – Mr Bonjour Apr 28 '16 at 12:55
  • Additionaly, if the library is already in the list make sure that it's marked as "Embed & Sign". This fixes my issue. – SquareBox Nov 26 '19 at 03:58
10

A simple restart of Xcode solved the issue for me.

Anton
  • 5,932
  • 5
  • 36
  • 51
5

For me, the issue was due to the fact that my Apple Worldwide Developer Relations Certification Authority was invalid.

Download it from here: https://developer.apple.com/certificationauthority/AppleWWDRCA.cer

Drag and drop it into Keychain Access, clean the project, and run.

Eric
  • 16,003
  • 15
  • 87
  • 139
  • This started happening after we added CloudKit entitlement. Prior to that, I guess it didn't care that the WWDR cert was invalid. – CommaToast Aug 12 '16 at 21:53
5

The reasons for this occurring are many. Having just spent a fun weekend finding yet another issue that causes this (the order of code signing), I wanted to create a summary answer that brings all the possible solutions together:

  1. Add Embedded Content Contains Swift Code to project. You need to set this flag if your app contains Swift code.
  2. Clean project. In addition to a Project > Clean you can also delete the DerivedData and Build directories. Look under the Preferences for the location of DerivedData. Build should be in your project folder.
  3. Ensure Runpath Search Paths contains @executable_path/Frameworks.
  4. Ensure that your certificate contains your Apple Team ID in the OU (Organization Unit) field Apple will add this for you, just revoke your existing distribution certificate and create a new one, download, install on KeyChain, regenerate all provisioning profiles, download those and rebuild.
  5. Xcode restart. If everything is basically good, but Xcode hasn't gotten there yet.

That's the easy stuff. If you are doing your own command line build you may be creating your own .ipa files to upload. In that case you need to ensure the following:

  1. Make sure the version of the Swift files in SwiftSupport/iphoneos is the same as the version in Contents/YourApp.app/Frameworks Because Swift is not yet binary compatible between version, you must ensure these versions are the one that you built your app with. You can find these libraries under /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos.
  2. Sign the libraries and frameworks first. You need to codesign the libraries and framework files (under Frameworks in the .app folder) first and then sign the entire .app tree. The .app tree must be signed with an entitlements.plist but not the frameworks.

Hopefully when Swift 3.0 comes out and we no longer need to bundle Swift with our apps this whole issue will go away.

jlyonsmith
  • 873
  • 11
  • 15
3

I had an Obj-C project where I started adding swift source files. The following fixed the issue for me:

  1. Linking: RUNPATH SEARCH PATHS = $(inherited) @executable_path/Frameworks
  2. Swift Compiler - Code Generation: EMBEDDED CONTENT CONTAINS SWIFT = YES

I just created a new project from the templates Xcode 6.3 and compared the project settings with my old original project.

lp_
  • 1,158
  • 1
  • 14
  • 21
pinzoni
  • 31
  • 2
3

Try to hold Alt, then go to Product -> Clean Build Folder...

Hope it will help someone..

stakahop
  • 921
  • 9
  • 18
  • This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/12420392) – Rakete1111 May 20 '16 at 15:04
  • It happened after trying to add a new class in old project. There is no information how old project is. So, clearing of project and force refreshing of cache make sense. Old project also implies there is a good chance that certificate is changed in meanwhile, because Apple Production and Developer certificates expire every year. Read about of main reason of error according to apple Technical Q&A at.https://developer.apple.com/library/ios/qa/qa1886/_index.html. Same thing happened to me and Clean Build Folder makes project run again. Let people try.. – stakahop May 20 '16 at 16:10
  • It happened just after reload my iOs certificate. A simple Clean (Product menu) and everything works fine ;-) – Sébastien REMY May 25 '16 at 06:53
  • Worked perfectly. Thank you. – iSofia Jul 07 '18 at 12:27
2

I had this issue using an Ad Hoc (or enterprise) mobileprovision with a production certificate. Switching to a development certificate and mobileprovision solved the issue.

MacTeo
  • 2,656
  • 1
  • 20
  • 23
2

My project is a Swift project with some Objective-C classes. I had the same problem when signed with old inHouse (enterprise) certificate.

The following steps fixed this for me.

  1. Create and use a new certificate and mobile provision.
    (Ref. AIRSIGN’s blog)
  2. Set Runpath Search Paths build setting to: $(inherited) @executable_path/Frameworks.
    (Ref. matt’s answer)
Community
  • 1
  • 1
jqgsninimo
  • 6,562
  • 1
  • 36
  • 30
2

Solution 6:

In our case, the Enterprise Distribution Certificate had been revoked. Generating a new certificate and updating the provisioning profile fixed the issue.

(There seems to be many different causes for this error. Hope this helps someone.)

picciano
  • 22,341
  • 9
  • 69
  • 82
  • This solved my issue. Holy crap what a waste of time trying to fix this. I hope this solves other users problems. I was able to debug my app with my custom framework but couldn't run the build machine's version on jenkins. Revoking my distribution certificates and generating a new enterprise provisioning profile fixed the builds for me. – cynistersix Nov 22 '14 at 01:37
  • 2
    This is same with Solution 4 – qwerty Dec 10 '14 at 15:45
2

I tried all the answers given above, nothing worked.

Finally worked after updating to Yosemite

Prabu
  • 2,313
  • 2
  • 28
  • 31
2

I have faced the same issue, setting the right code sign identity solved the problem(Build settings->Code Signing Identity).

As per Apple technical question "All Enterprise and standard iOS developer certificates that are created after iOS 8 was released have the new Team ID field in the proper place to allow Swift language apps to run"

Saikiran Komirishetty
  • 6,525
  • 1
  • 29
  • 36
2

If you add the three frameworks via Embedded Binaries, they will be added to Linked Frameworks and Libraries also. Delete the three entries in Linked Frameworks and Libraries will solve the problem.

Magic methods such as relaunch Xcode and restart the Mac doesn't work on me.

Arbipher
  • 81
  • 3
2

Adding Framework as "Embedded Binary" instead of just "Linked Frameworks and Libraries" - Fixed my issue.

I also set Embedded Content Contains Swift Code flag to YES.

Naveen Shan
  • 9,192
  • 3
  • 29
  • 43
1

Upgrade to Latest Version of OS X (Yosemite)

After hours of trial & error I came to the resolution of this problem. - If this applies to your case of course.

I had the same problem until I upgraded my Mac OS X from Mavericks to Yosemite. - It fixed my problem, hope it fixes yours as well

1

I tried all the solutions that found on web, including to Apple and new certificates. Without success.

The only way I could run xcode, after 6 months of trying, was creating a new account on my macbook.

1

Usually this error will disappear if you add this library to the "Copy Files" segment in your Build Phases.

raphael_mav
  • 580
  • 6
  • 23
  • This worked for me on XCode 7.2.1. I used the + in the Build Phases panel, selected New Copy Files Phase, then dragged the framework from the workspace tree into the Copy Files section. Finally I selected Destination: Frameworks. After a clean build, my application started as expected. – Rob Smallshire Mar 02 '16 at 11:16
1

My environment: Cocos2d 2.0, Box2d, Objective C

In addition to doing the other answers above I finally went to the General tab and made WatchKit Optional.

Targets:General:Linked Frameworks and Libraries: WatchKit.framework: Optional

Jim Rota
  • 1,781
  • 2
  • 16
  • 21
1

And if all of the above doesn't help you and you really get frustrated... Try the best trick of all: Clean and just to be sure also Clean Build Folder. :) Hope it helps somebody!

Georg
  • 3,664
  • 3
  • 34
  • 75
1

None of these solutions seemed to be consistently working for me; after every couple of successful runs, it would fail again. The "Embedded Content Contains Swift Code" flag was always set to YES for me.

Turns out I'd set Xcode to be 6.3-compatible. Changing it back to be 3.2-compatible solved it:

brandonscript
  • 68,675
  • 32
  • 163
  • 220
1

I've had this problem as well, only it wasn't locating libswiftXCTest.dylib.

The solution was to add XCTest.framework to the Tests target, in Build Phases/Link Binary with Library. I was getting this error even when I was trying to build the main target.

Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76
0

This showed up when I added a new Today extension target with Swift language to an old project. Fixed easily by updating the project to recommended settings. Xcode 6.0.1

Vilém Kurz
  • 3,401
  • 2
  • 34
  • 43
0

I got the same issue using Mavericks, Xcode 6.1.1, testing on an iPhone5 with iOS 8.1.1. I tried all possible solution including new certificates and provisioning profiles, but nothing helped. I did the changes to Embedded Content Contains Swift Code and Runpath Search Paths both on Project level and Target level.

I have now installed Yosemite, and without any further changes, it started to work.

patrik
  • 123
  • 8
0

Same issue here, for me it was Crashlytics/Fabric/Beta/Twitter/Whatever-they-call-themselves uploading a binary that was missing the embedded frameworks. If I made an archive and then exported an Enterprise build in the standard way, they worked a charm.

rob5408
  • 2,972
  • 2
  • 40
  • 53
0

After months and months trying everything here... Definition of insanity... starting Xcode under a new Mac user solved it for me.

I removed ~/Library/Developer/* and reinstalled Xcode- so no clue what else to format to make it work.

wcribbs
  • 56
  • 4
0

Recently started getting this error again. While the top 2 answers solved it for me in the past, none of the suggested answers worked this time. I noticed the error said:

 Reason: no suitable image found.  Did find:
/private/var/mobile/Containers/Bundle/Application/8D8E5347-940A-4724-ACFE-33DF4C4DCB37/your.app/Frameworks/libswiftCore.dylib: mmap() errno=1 validating first page of '/private/var/mobile/Containers/Bundle/Application/8D8E5347-940A-4724-ACFE-33DF4C4DCB37/your.app/Frameworks/libswiftCore.dylib'

So I tried deleting the app from device, and I was able to build and run again.

Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92
0

I added SCLAlertView pod in my project and later removed it. I did not remove import SCLAlertView from my viewcontroller. Ideally it should give a compile time error, but it gave a run time error mentioning dyld: Library not loaded: @rpath/SCLAlertView.framework. I removed import SCLAlertView from my viewcontroller, build it and it did not give the error. So in my case I was trying to import a library whose framework was not found. Removing such references will resolve your issue.

Deepak Thakur
  • 3,453
  • 2
  • 37
  • 65
0

I got the same problem. My solution is to move every pod declaration inside the target clause.

From:

pod 'SomePod1'
pod 'SomePod2'
pod 'SomePod3'
target 'MyAwesomeApp', :exclusive => true do

end

To:

target 'MyAwesomeApp', :exclusive => true do
    pod 'SomePod1'
    pod 'SomePod2'
    pod 'SomePod3'
end

My guess is that if the pod declarations are put outside the target declaration, CocoaPods(0.39.0) might use the wrong xcconfig.

Pods.debug.xcconfig (X

Pods-MyAwesomeApp.debug.xcconfig (O

Hai Feng Kao
  • 5,219
  • 2
  • 27
  • 38
0

With reference to https://forums.developer.apple.com/thread/21292

This solution worked for me :

It occurred on my side when building an app in the command line via xcodebuild and xcrun PackageApplication, signing the app with an enterprise profile. On our CI build servers, the certificate was set to "Always Trust" in the keychain (select certificate -> Get Info -> Trust -> "Use System Default" can be changed to "Always Trust"). I had to set it back to "Use System Default" in order to make this work. Initially we set this to "Always Trust" to work-around the keychain dialogs that appear after software updates and certificate updates.

Babul Prabhakar
  • 2,373
  • 1
  • 18
  • 25
0

in my case i just use "Cmd+Shift+K" and then "Cmd+B" run its work

Shakeel Ahmed
  • 5,361
  • 1
  • 43
  • 34
0

Ran into this problem after updating to Xcode 10.2 (Swift 5). Found the following Apple link that shows two options: https://support.apple.com/kb/DL1998?locale=en_US

For me, I updated the MacOS to 10.14.4 (which has Swift library included in OS). Otherwise, "Download Swift 5 Runtime Support for Command Line Tools" for older OS.

anorskdev
  • 1,867
  • 1
  • 15
  • 18