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

框架内SwiftUI预览异常求助(Rosetta模式下)

问题解决:Rosetta模式下SwiftUI框架预览架构不兼容错误

问题背景

在模块化应用的UI.xcodeproject框架中运行SwiftUIView预览时触发错误,但主目标内的ContentView、GradientView预览正常:

  • 涉及Xcode版本:14.0/14.1
  • 触发条件:开启Rosetta模式(因第三方依赖必须保留)
  • 已尝试无效操作:重建项目、清理Derived Data、修改Build for Active Architecture选项
  • 错误核心:预览代理尝试加载x86_64架构的SwiftUIView.1.preview-thunk.dylib,但实际需要arm64架构

错误日志

PotentialCrashError: Update failed

XCPreviewAgent may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application.

==================================

RemoteHumanReadableError
LoadingError: failed to load library at path "/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib": Optional(dlopen(/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib, 0x0002): tried: '/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Products/Debug-iphonesimulator/SwiftUIView.1.preview-thunk.dylib' (errno=2), '/Applications/Xcode_14.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib' (errno=2), '/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')))

|

==================================

解决方案

方案1:调整UI框架的排除架构设置

  • 选中UI.xcodeproject框架目标,进入Build Settings
  • 搜索Excluded Architectures,展开Debug-iphonesimulator配置
  • 添加x86_64到排除列表,强制框架为arm64架构编译预览产物
  • 清理Derived Data后重新尝试预览

方案2:显式设置框架的有效架构

  • 在Build Settings中,点击左上角+号,选择Add User-Defined Setting
  • 创建VALID_ARCHS设置,针对Debug-iphonesimulator配置,填入arm64
  • 确保Build Active Architecture Only在Debug配置下设置为YES
  • 重启Xcode并重新构建预览

方案3:修改框架Scheme的运行架构

  • 打开UI框架的Scheme(Product > Scheme > Edit Scheme)
  • 切换到Run标签页的Info选项卡
  • 将Architecture设置为arm64,而非Standard Architectures
  • 保存Scheme后重新尝试预览

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 12:10:37