Flutter构建Apple M1 Pro(arm64)macOS项目失败求助
在Apple M1 Pro(arm64)macOS上构建Flutter macOS应用的架构不兼容问题解决
问题场景
在Apple M1 Pro(arm64架构)的macOS 12.1系统中,使用Flutter 3.0.4创建并构建macOS应用时,执行flutter build macos命令出现架构不兼容错误,核心提示为快照要求x64-sysv架构,但当前VM为arm64-sysv,导致构建失败。
报错信息
$ flutter build macos Running "flutter pub get" in flutter_application_1... 234ms 💪 Building with sound null safety 💪 --- xcodebuild: WARNING: Using the first of multiple matching destinations: { platform:macOS, arch:arm64, id:00006000-000C09201A06801E } { platform:macOS, arch:x86_64, id:00006000-000C09201A06801E } Snapshot not compatible with the current VM configuration: the snapshot requires 'release no-code_comments no-dwarf_stack_traces_mode lazy_async_stacks lazy_dispatchers no-dedup_instructions no-asserts use_field_guards use_osr no-branch_coverage x64-sysv no-compressed-pointers no-null-safety' but the VM has 'release no-code_comments no-dwarf_stack_traces_mode lazy_async_stacks lazy_dispatchers no-dedup_instructions no-asserts use_field_guards use_osr no-branch_coverage arm64-sysv no-compressed-pointers no-null-safety' Command PhaseScriptExecution failed with a nonzero exit code ** BUILD FAILED ** Building macOS application... Build process failed
环境信息
项目创建命令:
flutter create --template app --platforms macos hello_world
工具版本:
$ flutter --version Flutter 3.0.4 • channel stable • https://github.com/flutter/flutter.git Framework • revision 85684f9300 (3 months ago) • 2022-06-30 13:22:47 -0700 Engine • revision 6ba2af10bb Tools • Dart 2.17.5 • DevTools 2.12.2 $ sw_vers ProductName: macOS ProductVersion: 12.1 BuildVersion: 21C52 $ xcodebuild -version Xcode 13.0 Build version 13A233
解决方案
方法一:命令行指定arm64架构构建
直接执行带架构指定参数的构建命令,强制Flutter针对arm64架构编译:
flutter build macos --dart-define=MACOS_ARCH=arm64
方法二:修改Xcode项目架构配置
如果命令行方式无效,可手动调整Xcode项目设置:
- 打开项目目录下的
macos/Runner.xcodeproj - 在Xcode中选择
Runner目标,切换到Build Settings标签 - 搜索
Architectures,将其设置为arm64(移除原有的x86_64选项) - 找到
Build Active Architecture Only,在Release模式下设置为YES - 清理Flutter缓存后重新构建:
flutter clean flutter build macos
方法三:升级Flutter到更新版本(可选)
部分旧版本Flutter在M1架构上的兼容性存在问题,可尝试切换到beta通道并升级:
flutter channel beta flutter upgrade flutter build macos
内容的提问来源于stack exchange,提问作者Kamil Zaripov
相关产品推荐
相关产品推荐

