我该如何在构建Flutter macOS应用时更改MACOSX_DEPLOYMENT_TARGET?

15

我正在使用以下命令在macOS(v12.4 M1芯片)上构建flutter(v3.0.4)的macOS应用:

~/fvm/versions/3.0.4/bin/flutter build macos --release

显示错误信息如下:

    ➜  macos git:(main) ✗ ~/fvm/versions/3.0.4/bin/flutter build macos --release --no-tree-shake-icons
Changing current working directory to: /Users/xiaoqiangjiang/source/reddwarf/frontend/tik

 Building with sound null safety 

Running pod install...                                             668ms
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006000-001248980AE2801E }
{ platform:macOS, arch:x86_64, id:00006000-001248980AE2801E }
/Users/xiaoqiangjiang/source/reddwarf/frontend/tik/macos/Pods/Pods.xcodeproj: warning: The macOS deployment target 'MACOSX_DEPLOYMENT_TARGET' is set to 10.6, but the range of supported deployment target versions is 10.9 to 12.3.99. (in target 'FMDB' from project 'Pods')
Building macOS application...

我已经将Pods和Runner的部署目标更改为10.11。那我应该如何更改MACOSX_DEPLOYMENT_TARGET版本呢?这是macOS的Podfile:

platform :osx, '10.11'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_macos_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_macos_build_settings(target)
  end
end

这是Pods macOS的部署配置:

enter image description here

我已经尝试清理构建并重新构建macOS应用程序,但仍然不能按预期工作。

5个回答

33

进入我的macOS/Podfile文件,并替换掉原来的post_install方法,修改后如下所示...

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_macos_build_settings(target)
  end
end

看起来像这样,而不是那样。

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_macos_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.15'
    end
  end
end

来源: https://levelup.gitconnected.com/how-to-fix-your-flutter-macos-target-mismatch-bc55424b7c77

希望对您有所帮助!


这适用于iOS,但不适用于MacOS。 - Oliver Dixon

6
在Xcode中打开macos文件夹,选择项目导航器中的Pods。选择框架目标并选择常规选项卡。

更改这些部署目标中的Pods并保存更改即可解决该问题。


我在Xcode中检查过了,并已将版本更改为10.11@Ali Hassan。 - Dolphin

3
在寻找解决方案几个小时后,找到了答案。
需要在同一个文件的两个位置进行更改。 该文件是macos/Runner.xcworkspace。
在Finder中找到它,并使用XCode打开。
第一次更改文件: Runner > General > 最小部署。 在列表中设置为最小或所需值(在我的情况下为10.13)。
文件中的第二次更改: Flutter Assemble > Build Settings > macOS部署目标。 设置为与之前相同的值(在我的情况下为10.13)。
要切换到Flutter Assemble,请使用Runner下面的子菜单。这是我的困惑。这两个更改需要在同一个文件中进行,并且只能在Runner的上方菜单下选择Runner或Flutter Assemble。
请参阅以下视频以获取详细信息。

https://youtu.be/iqGHugqyDiM

希望这可以帮到您。
附上两张照片。 跑步者 > 通用 > 最小部署

Flutter Assemble > Build Settings > macOS Deployment Target


1
在Xcode中选择目标,然后选择构建设置。确保它显示了组合选项。检查有效架构。删除您未使用的架构。
另外,请备份项目并运行 pod install --repo-update

preview


0
我能够通过编辑macos/Podfile并将第一行替换为我所需的版本10.15来更改macOS的部署目标版本。就像这样:
platform :osx, '10.15'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接