I've built a Swift framework and now I'm trying to start building a Swift iOS application that will use that framework. I'm getting this error:
我已经构建了一个Swift框架,现在我正在尝试构建一个将使用该框架的Swift iOS应用程序。我收到这个错误:
dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: /Users/tdean/Library/Developer/Xcode/DerivedData/NFLApplication-ejmafvjrlqgjaabggwvadjarjjlg/Build/Products/Debug-iphonesimulator/NFLStatsModel.framework/NFLStatsModel
Reason: image not found
I've scoured SO and found similar reports and tried the fixes listed there, including:
我搜索了SO并找到了类似的报告并尝试了其中列出的修复程序,包括:
- Clearing out my DerivedData folder
- 清除我的DerivedData文件夹
- Restarting Xcode and the iPhone simulator
- 重新启动Xcode和iPhone模拟器
- Ensuring that
Always Embed Swift Standard Libraries = YES
is set, both in my framework and my application's build settings - 在我的框架和我的应用程序的构建设置中确保始终嵌入Swift标准库= YES
- Ensuring that
Enable Bitcode=NO
is set, both in my framework and my application's build settings - 确保在我的框架和我的应用程序的构建设置中设置了Enable Bitcode = NO
- Ensuring that
Runpath Search Paths
is set to@executable_path/Frameworks
, both in my framework and my application's build settings - 确保在我的框架和我的应用程序的构建设置中将Runpath搜索路径设置为@ executable_path / Frameworks
- Copied all the libswift files from my Xcode installation into a local copy within my project, and added a custom build phase to copy those files into the frameworks folder.
- 将我的Xcode安装中的所有libswift文件复制到项目中的本地副本中,并添加了自定义构建阶段以将这些文件复制到frameworks文件夹中。
In every case, I get the same error when I try to run my application.
在每种情况下,当我尝试运行我的应用程序时,我都会收到相同的错误。
- Xcode Version 8.1 (8B62)
- Xcode版本8.1(8B62)
- Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)
- Apple Swift 3.0.1版(swiftlang-800.0.58.6 clang-800.0.42.1)
2 个解决方案
#1
31
I eventually got this working using a mix of fixes. I'm not sure if all of them are needed, but I'm documenting what seemed to work for me here, just in case anyone else can benefit by what I've found.
我最终使用了各种修复工具。我不确定是否所有这些都是必需的,但我在这里记录似乎对我有用的东西,以防万一其他人可以从我发现的东西中受益。
- I have set
Always Embed Swift Standard Libraries
to a value ofYES
in the build settings tab for both my Swift framework and in the Swift application that uses the framework. - 我在构建设置选项卡中为我的Swift框架和使用该框架的Swift应用程序中的Always Embed Swift标准库设置了值YES。
- I have added
Foundation.framework
to the Linked Frameworks and Libraries section of the general tab for both my Swift framework and in the Swift application that uses the framework. - 我已将Foundation.framework添加到我的Swift框架和使用该框架的Swift应用程序的常规选项卡的Linked Frameworks and Libraries部分。
- I have added
Foundation.framework
to the Embedded Binaries section of the general tab for the Swift application that uses the framework. - 我已将Foundation.framework添加到使用该框架的Swift应用程序的常规选项卡的嵌入式二进制文件部分。
With all 3 of these settings in place, I am able to build and run my application without encountering this error.
有了所有这三个设置,我就可以构建并运行我的应用程序而不会遇到此错误。
#2
5
How are you installing your dependencies?
你是如何安装依赖项的?
I had a similar issue:
我有一个类似的问题:
dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib Referenced from: <internal framework> Reason: image not found
dyld:未加载库:@ rpath / libswiftSwiftOnoneSupport.dylib引用自: <内部框架> 原因:未找到图像
It turned out to be related to Swift whole-module optimization.
事实证明这与Swift整体模块优化有关。
Using Carthage as a dependency manager, they were being compiled for Release, and thus compiled with whole-module optimization, which Xcode suggested I turn on. Running the app on the simulator compiles it for Debug. I'm guessing that dynamic frameworks cannot be at a different level of optimization from the app running it.
使用Carthage作为依赖管理器,它们被编译为Release,因此使用整个模块优化进行编译,Xcode建议我打开它。在模拟器上运行应用程序将其编译为Debug。我猜测动态框架不能与运行它的应用程序处于不同的优化级别。
The solution was to explicitly specify the configuration I wanted Carthage to build for. (carthage bootstrap --configuration Debug
) Oh, and cleaning my build folder, of course.
解决方案是明确指定我希望Carthage构建的配置。 (carthage bootstrap --configuration Debug)哦,然后清理我的build文件夹。
#1
31
I eventually got this working using a mix of fixes. I'm not sure if all of them are needed, but I'm documenting what seemed to work for me here, just in case anyone else can benefit by what I've found.
我最终使用了各种修复工具。我不确定是否所有这些都是必需的,但我在这里记录似乎对我有用的东西,以防万一其他人可以从我发现的东西中受益。
- I have set
Always Embed Swift Standard Libraries
to a value ofYES
in the build settings tab for both my Swift framework and in the Swift application that uses the framework. - 我在构建设置选项卡中为我的Swift框架和使用该框架的Swift应用程序中的Always Embed Swift标准库设置了值YES。
- I have added
Foundation.framework
to the Linked Frameworks and Libraries section of the general tab for both my Swift framework and in the Swift application that uses the framework. - 我已将Foundation.framework添加到我的Swift框架和使用该框架的Swift应用程序的常规选项卡的Linked Frameworks and Libraries部分。
- I have added
Foundation.framework
to the Embedded Binaries section of the general tab for the Swift application that uses the framework. - 我已将Foundation.framework添加到使用该框架的Swift应用程序的常规选项卡的嵌入式二进制文件部分。
With all 3 of these settings in place, I am able to build and run my application without encountering this error.
有了所有这三个设置,我就可以构建并运行我的应用程序而不会遇到此错误。
#2
5
How are you installing your dependencies?
你是如何安装依赖项的?
I had a similar issue:
我有一个类似的问题:
dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib Referenced from: <internal framework> Reason: image not found
dyld:未加载库:@ rpath / libswiftSwiftOnoneSupport.dylib引用自: <内部框架> 原因:未找到图像
It turned out to be related to Swift whole-module optimization.
事实证明这与Swift整体模块优化有关。
Using Carthage as a dependency manager, they were being compiled for Release, and thus compiled with whole-module optimization, which Xcode suggested I turn on. Running the app on the simulator compiles it for Debug. I'm guessing that dynamic frameworks cannot be at a different level of optimization from the app running it.
使用Carthage作为依赖管理器,它们被编译为Release,因此使用整个模块优化进行编译,Xcode建议我打开它。在模拟器上运行应用程序将其编译为Debug。我猜测动态框架不能与运行它的应用程序处于不同的优化级别。
The solution was to explicitly specify the configuration I wanted Carthage to build for. (carthage bootstrap --configuration Debug
) Oh, and cleaning my build folder, of course.
解决方案是明确指定我希望Carthage构建的配置。 (carthage bootstrap --configuration Debug)哦,然后清理我的build文件夹。