dyld: Library not loaded: @rpath/libswiftCore.dyli

2018-12-31 07:45发布

I am trying to run a Swift app on my iPhone 4s. It works fine on the simulator, and my friend can successfully run it on his iPhone 4s. I have iOS 8 and the official release of Xcode 6.

I have tried

  • Restarting Xcode, iPhone, computer
  • Cleaning & rebuilding
  • Revoking and creating new certificate/provision profile
  • Runpath Search Paths is $(inherited) @executable_path/Frameworks
  • Embedded Content Contains Swift Code is 'Yes'
  • Code Signing Identity is developer

Below is the error in entirety

dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /private/var/mobile/Containers/Bundle/Application/LONGSERIALNUMBER/AppName.app/AppName
  Reason: no suitable image found.  Did find:
    /private/var/mobile/Containers/Bundle/Application/LONGSERIALNUMBER/AppName.app/Frameworks/libswiftCore.dylib: mmap() error 1 at
address=0x008A1000, size=0x001A4000 segment=__TEXT in Segment::map() mapping
/private/var/mobile/Containers/Bundle/Application/LONGSERIALNUMBER/APPLICATION_NAME/Frameworks/libswiftCore.dylib

标签: ios xcode swift
30条回答
美炸的是我
2楼-- · 2018-12-31 08:01

I think Apple has already summarized it under Swift app crashes when trying to reference Swift library libswiftCore.dylib

Cited from Technical Q&A QA1886:

Swift app crashes when trying to reference Swift library libswiftCore.dylib.

Q: What can I do about the libswiftCore.dylib loading error in my device's console that happens when I try to run my Swift language app?

A: To correct this problem, you will need to sign your app using code signing certificates with the Subject Organizational Unit (OU) set to your Team ID. 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.

Usually this error appears in the device's console log with a message similar to one of the following:

[....] [deny-mmap] mapped file has no team identifier and is not a platform binary:
/private/var/mobile/Containers/Bundle/Application/5D8FB2F7-1083-4564-94B2-0CB7DC75C9D1/YourAppNameHere.app/Frameworks/libswiftCore.dylib

Dyld Error Message:
  Library not loaded: @rpath/libswiftCore.dylib

Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000120021088
Triggered by Thread: 0

Referenced from: /private/var/mobile/Containers/Bundle/Application/C3DCD586-2A40-4C7C-AA2B-64EDAE8339E2/TestApp.app/TestApp
Reason: no suitable image found. Did find:
/private/var/mobile/Containers/Bundle/Application/C3DCD586-2A40-4C7C-AA2B-64EDAE8339E2/TestApp.app/Frameworks/libswiftCore.dylib: mmap() error 1 at address=0x1001D8000, size=0x00194000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Bundle/Application/C3DCD586-2A40-4C7C-AA2B-64EDAE8339E2/TestApp.app/Frameworks/libswiftCore.dylib
Dyld Version: 353.5

The new certificates are needed when building an archive and packaging your app. Even if you have one of the new certificates, just resigning an existing swift app archive won’t work. If it was built with a pre-iOS 8 certificate, you will need to build another archive.

Important: Please use caution if you need to revoke and setup up a new Enterprise Distribution certificate. If you are an in-house Enterprise developer you will need to be careful that you do not revoke a distribution certificate that was used to sign an app any one of your Enterprise employees is still using as any apps that were signed with that enterprise distribution certificate will stop working immediately. The above only applies to Enterprise Distribution certificates. Development certs are safe to revoke for enterprise/standard iOS developers.

As the AirSign guys state the problem roots from the missing OU attribute in the subject field of the In-House certificate.

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

I have an enterprise development certificate, creating a new one solved the issue.

查看更多
听够珍惜
3楼-- · 2018-12-31 08:01

In my case,

I have set @executable_path/Frameworks

But I have to also set "Framework search paths"

$(PROJECT_DIR)/Frameworks

change as recursive

Which works for me.

查看更多
零度萤火
4楼-- · 2018-12-31 08:02

OK, sharing here another cause of this error. It took me a few hours to sort this out.

In my case the trust policy of my certificate in Keychain Access was Always Trust, changing it back to defaults solved the problem.

In order to open the certificate settings window double click the certificate in the Keychain Access list of certificates.

enter image description here enter image description here

查看更多
后来的你喜欢了谁
5楼-- · 2018-12-31 08:06

You have to set the Runpath Search Paths to @executable_path/Frameworks as showed in the following screenshot of Build Settings:

enter image description here

If you have any embedded frameworks made in Swift, than you can set to YES the Build Options Embedded Content Contains Swift Code.

查看更多
君临天下
6楼-- · 2018-12-31 08:06

Change Copy Pods Resources for the target from:

"${SRCROOT}/Pods/Target Support Files/Pods-Wishlist/Pods-Wishlist-resources.sh"

to:

"${SRCROOT}/Pods/Target Support Files/Pods-Wishlist/Pods-Wishlist-frameworks.sh"
查看更多
与风俱净
7楼-- · 2018-12-31 08:07

This error message can also be caused when upgrading Xcode (and subsequently to a new version of Swift) and your project uses a framework built/compiled with an older/previous version of Swift.

In this case rebuilding the framework and re-adding it will fix the problem.

查看更多
登录 后发表回答