要开发适用于iOS的Flutter应用,您需要一台装有Xcode的Mac。Xcode 11.4更改了框架的链接和嵌入方式,在iOS设备和模拟器之间切换时,您可能会看到以下错误:
content_copy
Building for iOS, but the linked and embedded framework 'App.framework' was built for iOS Simulator.
要么
content_copy
Building for iOS Simulator, but the linked and embedded framework 'App.framework' was built for iOS.
Flutter v1.15.3及更高版本会自动迁移Xcode项目。
如果需要手动升级项目,请使用以下步骤:
- 在Flutter应用程序目录中,
ios/Runner.xcworkspace
以Xcode 打开。 - 在“ 导航器”窗格中,找到 Flutter组,然后删除
App.framework
和Flutter.framework
。 - 在Runner目标构建设置中,选择“ 构建阶段”>“使用库链接二进制文件”进行 确认
App.framework
,Flutter.framework
并且不再存在。还要在“ 构建阶段”>“嵌入框架”中进行确认。 如下更改Runner目标构建设置 Build Phases> Thin Binary脚本:
content_copy/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" thin
- 在Runner目标的Build Settings> Other Linker Flags(
OTHER_LDFLAGS
)中添加$(inherited) -framework Flutter
。