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

Xcode 16.2中SwiftUI预览因架构不兼容无法使用求助

问题背景
  • 环境:Xcode 16.2,MacBook Pro M3 Pro
  • 问题:现有项目引入DotLottie、swiftui-mail-view等SPM依赖后,SwiftUI预览功能失效;但新建项目安装相同依赖后预览正常
  • 核心报错:

    Build failed because DotLottie.swiftmodule is not built for arm64. Would you like to show all run destinations instead?
    Ensure all targets are configured to build for standard architectures. If your project uses external dependencies, contact those vendors to provide updated copies built to support all architectures. You can control the visibility of architecture-specific run destinations in the Product > Destination menu.
    == PREVIEW UPDATE ERROR:
    SchemeBuildError: Failed to build the scheme “Tenki Weather”
    could not find module 'DotLottie' for target 'x86_64-apple-ios-simulator'; found: arm64-apple-ios-simulator, at: /Users/me/Library/Developer/Xcode/DerivedData/projectname/Build/Intermediates.noindex/Previews/iphonesimulator/myapp/Products/Debug-iphonesimulator/DotLottie.swiftmodule

  • 已尝试无效操作:删除Derived Data、重新添加SPM依赖、将x86_64加入排除架构
  • 额外异常:添加模拟器时默认出现Rosetta版本,怀疑项目或模拟器设置被篡改
解决步骤

1. 恢复项目架构默认配置

打开项目根节点(Project Navigator最顶部),依次检查全局和所有Target的Build Settings:

  • 搜索Architectures,设置为$(ARCHS_STANDARD),确保Excluded Architectures为空(不要手动添加x86_64)
  • 搜索Build Active Architecture Only,Debug设为Yes,Release设为No
  • 切换到Info标签页,确认Configurations下所有环境的Architectures为Standard Architectures (arm64)

2. 重置模拟器并移除Rosetta设备

  • 关闭Xcode和模拟器,打开终端执行以下命令清除模拟器缓存:
    rm -rf ~/Library/Developer/CoreSimulator/Devices
    rm -rf ~/Library/Developer/Xcode/iOS DeviceSupport
    
  • 重新打开模拟器,执行Simulator > Reset Content and Settings...完成重置
  • 打开Xcode的Window > Devices and Simulators,删除所有带“Rosetta”标识的模拟器
  • 添加新模拟器时,确保不勾选**“Use Rosetta for x86_64 emulation on Apple Silicon”**选项

3. 修复SPM依赖构建问题

  • 进入项目的Package Dependencies页面,更新DotLottie等依赖到最新版本
  • 若更新无效,删除依赖后重新添加,优先选择Exact Version而非分支版本
  • 执行Cmd+Shift+K清理构建文件夹,再重新尝试SwiftUI预览

4. 重置Xcode项目工作区

  • 关闭Xcode,删除项目目录下的.xcworkspace文件,以及.xcodeproj内的xcuserdata和project.xcworkspace文件夹
  • 重新打开.xcodeproj,Xcode会自动重建工作区配置
  • 重新添加SPM依赖并测试预览

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 17:39:54