dyld:库未加载:@rpath/libswiftCore.dylib。

465

我正在尝试在我的iPhone 4s上运行一款Swift应用程序。它在模拟器上运行良好,我的朋友也可以在他的iPhone 4s上成功运行它。我使用的是iOS 8和Xcode 6正式版本。

我已经尝试了以下:

  • 重启Xcode、iPhone、电脑
  • 清理并重新构建
  • 吊销并创建新的证书/配置文件
  • Runpath搜索路径为$(inherited) @executable_path/Frameworks
  • 嵌入内容包含Swift代码是'Yes'
  • 代码签名标识是开发者

下面是完整的错误信息:

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

2
可能是一个重复问题:dyld: Library not loaded: @rpath/libswift_stdlib_core.dylib - Sruit A.Suk
4
清理并重新构建对我有用。 - MoralCode
解决方案在这里。同一主题。 - Tarik
清理并重新构建我的项目,使其能够正常工作。 - Syed Zahid Shah
我曾经遇到过同样的问题... 我通过添加以下内容解决了它:在您的podfile中:使用 use_modular_headers! 代替 use_frameworks!祝好运!希望这对你有用! - XtremeDevX
59个回答

1
我正在使用 Xcode 8.3.2。对我来说,问题在于 AppleWWDRCA 证书同时存在于系统和登录钥匙串中。将两者都删除,然后添加到登录钥匙串中,现在它可以正常运行了。浪费了两天时间。

你能否提供更详细的答案呢?你在哪里找到它(证书)- 我猜你写的是苹果全球开发者某事...但全名是什么?如果你从所有密钥链中完全删除了它,如何重新添加它?你在哪里找到这个证书? - Motti Shneor

1
我同时安装了多个版本的Xcode。该框架是使用较新版本的Xcode构建的。我尝试编译的应用程序使用的是较旧版本的Xcode。当我使用相同版本的Xcode清理和编译框架和应用程序时,一切都正常工作。

1
如果你遇到以下错误:
引用块: “YourFrameworkTests”包无法加载,因为它已损坏或缺少必要的资源。 尝试重新安装该包。 (dlopen_preflight(/some/path/.../YourFrameworkTests.xctest/YourFrameworkTests): 未加载库:@rpath/SomeOther.framework/SomeOther 参考自:/some/path/...)
并且在你的框架中使用了CocoaPods,那么请尝试编辑Podfile,并从Test目标中删除inherit!:search_paths,然后再次运行pod install。
更多详情,请参见https://github.com/CocoaPods/CocoaPods/issues/8868

1

1
对于 Xcode 12.x,我的解决方法是进入"General" -> "Frameworks, Libraries, and Embedded Content",然后选择嵌入并签署所有 Agora 框架。(默认情况下为不嵌入)

enter image description here


1

我试图阅读所有答案(可能错过了一些),但这是我的解决方案,可能对某些人有帮助。我在我的项目中创建了一个Swift文件(void.swift)。当我添加这个文件时,它要求我创建一个桥接文件,我选择了是。就这样!它开始工作了。 背景:我的项目是用Objective-C编写的。我添加了FBSDK pods到我的项目中后,开始出现这个错误。


太棒了!它帮了我大忙(尽管我正在使用React Native)。 - Sergii

1

对于我来说,以上解决方案都没有起作用。

我通过在项目中创建一个空的Swift文件来解决了这个问题。之后进行一次清理构建,一切都正常工作了!

希望这可以帮助其他人。

已在iOS 15React Native 0.66上测试。


1
我正在使用Xcode 8.3.3和Xcode 9.2。对我来说,解决方案是使用Xcode Select将默认的Xcode从8切换到9: $ xcode-select --print-path $ sudo xcode-select -switch /Applications/Xcode-9.2.app 编辑:实际上,这里似乎有所帮助的是Xcode 9.2使用了来自Xcode 8.3.3的派生数据。这不是一个解决方案,但至少它让我能够继续我的工作。

我尝试过这个问题,但当我退出并重新启动Xcode时,它就可以工作了。:)不错的尝试。 - Abhishek Thapliyal

0

在我的情况下,

我已经设置了@executable_path/Frameworks

但我还必须设置 "Framework search paths"

$(PROJECT_DIR)/Frameworks

改为递归

这对我来说可行。


0

我遇到了同样的问题。

那里有很多答案,但也许我的答案能帮助某个人。

// MARK: - Core Data堆栈

 lazy var persistentContainer: NSPersistentContainer = {
            /*
             The persistent container for the application. This implementation
             creates and returns a container, having loaded the store for the
             application to it. This property is optional since there are legitimate
             error conditions that could cause the creation of the store to fail.
            */
            let mom = NSManagedObjectModel.mergedModel(from: [Bundle(for: Self.self)])!
            
            let container = NSPersistentContainer(name: "Test", managedObjectModel: mom)
            container.loadPersistentStores(completionHandler: { (storeDescription, error) in
                if let error = error as NSError? {
                    // Replace this implementation with code to handle the error appropriately.
                    // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                     
                    /*
                     Typical reasons for an error here include:
                     * The parent directory does not exist, cannot be created, or disallows writing.
                     * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                     * The device is out of space.
                     * The store could not be migrated to the current model version.
                     Check the error message to determine what the actual problem was.
                     */
                    fatalError("Unresolved error \(error), \(error.userInfo)")
                }
            })
            return container
        }()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接