Xcode 升级后,多个命令出现 Flutter iOS 构建失败错误

Flutter iOS build failure error with Multiple commands after the Xcode upgrade

Flutter iOS 在 mac 中升级到 Xcode 10.0 版本后构建失败。

Nagendras-MacBook-Pro:uaenumber nagendra$ flutter run
Launching lib/main.dart on iPhone X in debug mode...
Starting Xcode build...
Xcode build done.                                            1.4s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **

Xcode's output:
↳
    error: Multiple commands produce '/Users/dev/Documents/projects/Personal/uaenumber/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework':
    1) Target 'Runner' has copy command from '/Users/dev/Documents/projects/Personal/uaenumber/ios/Flutter/Flutter.framework' to '/Users/dev/Documents/projects/Personal/uaenumber/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework'
    2) That command depends on command in Target 'Runner': script phase “[CP] Embed Pods Frameworks”
    warning: The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objcinference” logging enabled, and then disable inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "Runner" target. (in target 'Runner')
    warning: ignoring duplicated output file: '/Users/nagendra/Documents/projects/Personal/uaedialer/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework' (in target 'Runner')
    note: Using new build systemnote: Planning buildnote: Constructing build description
Could not build the application for the simulator.
Error launching application on iPhone X.

Xcode 版本 - 10.0 (10A255)

我尝试重新创建项目并将所有源文件复制到新的项目文件夹,但没有解决问题。

这是一个已知问题。这是解释和一些解决方法: https://github.com/flutter/flutter/issues/20685#issuecomment-421511890

Affected projects

This issue affects all Flutter projects built using Xcode 10 that have a dependency on CocoaPods -- typically this means those that rely on plugins. Workarounds

There are two workarounds:

  • Option 1: Use the legacy build system . As noted by @gi097, open ios/Runner.xcworkspace, and change the build system to Legacy Build System.
  • Option 2: Use the new Xcode 10 build system. Open ios/Runner.xcworkspace Select the Runner project in the project navigator sidebar. In the main view, select the Runner target, then select the Build Phases tab. Expand the Embed Frameworks phase and select Flutter.framework from the embedded frameworks list. Click - to remove Flutter.framework from the list (be sure to keep App.framework).

Root cause

When plugins are in use, there are two competing build actions that copy Flutter.framework into the build application Frameworks directory:

The Embed Frameworks build phase for the Runner project

The [CP] Embed Pods Frameworks build phase that pod install creates in the project.

Item (1) is there to ensure the framework is copied into the built app in the case where there are no plugins (and therefore no CocoaPods integration in the Xcode project). Item (2) is there because Flutter's podspec declares Flutter.framework as a vended_framework, and CocoaPods automatically adds a copy step for each such vended_framework in the transitive closure of CocoaPods dependencies.

这个解决方案对我有用。

  1. 打开ios/Runner.xcworkspace Select工程中的Runner工程 导航器侧边栏。
  2. 在主视图中,select 运行器目标,然后是 select 构建阶段选项卡。
  3. 展开嵌入框架阶段和 select Flutter.framework 嵌入式框架列表。
  4. 单击 - 从列表中删除 Flutter.framework(务必保留 App.framework).

此问题已通过在 Xcode 10 中打开 Runner 工作区项目得到修复。然后导航到“文件”、“工作区设置”并将构建系统更改为“旧版构建系统”。

编辑: Flutter 的最新稳定版本会将您的 Xcode 项目迁移到新的构建系统(下面的第一步)并完全避免多个嵌入式框架警告.如果没有,请按照 https://flutter.dev/docs/development/ios-project-migration 中的说明进行操作。您不再需要编辑 Podfile(下面的第二步)。

https://github.com/flutter/flutter/issues/20685#issuecomment-622126064

上一个回答

  1. 在 Xcode 中打开 ios/Runner.xcworkspace。文件 > 工作区设置... > 构建系统,将下拉菜单更改为新构建系统(默认)
  2. 在您的 Podfile 中,添加行
install! 'cocoapods', :disable_input_output_paths => true

3. 在您的 Flutter 应用程序中,再次构建以触发 pod install,这将自动清理构建阶段

flutter build ios

见: https://github.com/flutter/flutter/issues/20685#issuecomment-509731873 https://github.com/flutter/flutter/issues/20685#issuecomment-510162863

警告: 不要按照其他答案中的建议恢复到 Xcode 已弃用的遗留构建系统来解决此问题。

我今天遇到了这个问题,但没有解决。然后我检查我的 xcode 项目,我发现 insider runner 文件夹我发现另一个 runner 显示红色,以前不存在。所以我删除它并重新运行我的项目,它解决了我的问题。

我尝试了上面的方法,但没有解决我的问题。不过你可以两种都试试,看看哪一种适合你。

如果您已经尝试了所有方法但仍然无法成功构建 Archive,那么您看起来像我的情况。

我花了 3 个工作日来解决这个问题。我的问题发生在将 Notification Services 目标添加到项目后。但它看起来也适用于许多其他情况:

问题是2个target里面的库多个命令产生的。在我的例子中,例如,在项目目标和通知扩展目标中,GoogleUtilities 都有这导致它们冲突或重复命令生成。解决方案是在顶层使该依赖关系显式。 Pod 文件将如下所示:

platform :ios, '10.0'
use_frameworks!
inhibit_all_warnings!

pod 'GoogleUtilities' // Add this line is very important.

target 'MyProject' do
  pod 'Firebase/Analytics'
  pod 'Firebase/Crashlytics'
  pod 'Firebase/Messaging'
# Other pods
end

target 'NotificationService' do
  pod 'Firebase/Messaging'
end

运行之后:

pod deintegrate
pod install