You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS项目构建失败:Library not loaded: @rpath/Alamofire.framework/Alamofire

解决iOS项目Alamofire动态库加载失败问题

错误信息

dyld[42806]: Library not loaded: @rpath/Alamofire.framework/Alamofire
  Referenced from: <09986113-043E-33EF-8AE9-D34818E16FDC> /private/var/containers/Bundle/Application/C3F03E0F-0E58-40A5-96F6-1CED2574404E/Ordo.app/Ordo
  Reason: tried: '/usr/lib/swift/Alamofire.framework/Alamofire' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/Alamofire.framework/Alamofire' (no such file), '/usr/lib/swift/Alamofire.framework/Alamofire' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/Alamofire.framework/Alamofire' (no such file), '/private/var/containers/Bundle/Application/C3F03E0F-0E58-40A5-96F6-1CED2574404E/Ordo.app/Frameworks/Alamofire.framework/Alamofire' (no such file), '/private/var/containers/Bundle/Application/C3F03E0F-0E58-40A5-96F6-1CED2574404E/Ordo.app/Frameworks/Alamofire.framework/Alamofire' (no such file), '/private/var/containers/Bundle/Application/C3F03E0F-0E58-40A5-96F6-1CED2574404E/Ordo.app/Frameworks/Alamofire.framework/Alamofire' (no such file), '/usr/lib/swift/Alamofire.framework/Alamofire' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/Alamofire.framework/Alamofire' (no such file), '/usr/lib/swift/Alamofire.framework/Alamofire' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/Alamofire.framework/Alamofire' (no such file), '/private/var/containers/Bundle/Application/C3F03E0F-0E58-40A5-96F6-1CED2574404E/Ordo.app/Frameworks/Alamofire.framework/Alamofire' (no such file), '/private/var/containers/Bundle/Application/C3F03E0F-0E58-40A5-96F6-1CED2574404E/Ordo.app/Frameworks/Alamofire.framework/Alamofire' (no such file), '/private/var/containers/Bundle/Application/C3F03E0F-0E58-40A5-96F6-1CED2574404E/Ordo.app/Frameworks/Alamofire.framework/Alamofire' (no such file), '/System/Library/Frameworks/Alamofire.framework/Alamofire' (no such file, not in dyld cache)

排查与修复步骤

1. 检查Build Phases中的框架嵌入状态

  • 打开项目target的Build Phases标签
  • 确认Link Binary With Libraries中存在Alamofire.framework,且状态为Required
  • 切换到Embed Frameworks,确保Alamofire.framework已添加,且Embed选项设为Embed & Sign(CocoaPods通常自动配置,需手动验证)

2. 彻底清理并重装CocoaPods

  • 打开Podfile,确保Alamofire配置无特殊架构限制,示例:
    pod 'Alamofire', '~> 5.8'
    
  • 执行以下命令完成彻底清理:
    pod deintegrate
    rm -rf Podfile.lock
    rm -rf ~/Library/Caches/CocoaPods
    rm -rf ./Pods
    pod install --repo-update
    
  • 确保后续打开的是.xcworkspace文件,而非.xcodeproj

3. 验证Runpath Search Paths配置

  • 进入target的Build Settings,搜索Runpath Search Paths
  • 确认配置包含以下路径:
    @executable_path/Frameworks
    @loader_path/Frameworks
    

4. 清理Xcode缓存与构建产物

  • 执行Product > Clean Build Folder(快捷键Cmd+Shift+K)
  • 删除DerivedData目录:
    rm -rf ~/Library/Developer/Xcode/DerivedData
    
  • 重启Xcode后重新构建项目

5. 确认真机架构与签名配置

  • 检查target的Build Settings中Architectures设置为Standard Architectures (ARM64)
  • 验证Signing & Capabilities中的开发者证书和Provisioning Profile有效,真机调试与TestFlight上传的签名配置保持一致
  • 确保Alamofire的编译架构包含ARM64(CocoaPods默认配置,可通过pod spec cat Alamofire验证)

6. 排查重复框架引用

  • 确认项目未同时通过CocoaPods和手动方式导入Alamofire,避免冲突
  • 搜索项目目录,删除所有手动添加的Alamofire相关文件或框架

内容的提问来源于stack exchange,提问作者Shubham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 07:44:59