如何解决Flutter中iOS部署目标问题

18

我在构建Flutter应用程序时,针对iOS平台重复遇到与IPHONEOS_DEPLOYMENT_TARGET相关的问题,我不知道该如何解决。

warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'firebase_core' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'firebase_auth' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'firebase_storage' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'firebase_messaging' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'firebase_analytics' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'cloud_functions' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'cloud_firestore' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'Flutter' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'Firebase' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'GoogleAppMeasurement' from project 'Pods')
warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.1.99. (in target 'FirebaseAnalytics' from project 'Pods')

我的iOS Flutter项目的Pod文件在这里

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# 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', '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 Generated.xcconfig, then run flutter pub get"
end

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

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

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

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

我在 Xcode 中打开项目后检查了版本设置,但是无法理解应该如何纠正它。请指导如何修复 IPHONEOS_DEPLOYMENT_TARGET。

3个回答

36

在你的./ios/Podfile中取消注释:

# platform :ios, '9.0' 

关于

platform :ios, '9.0'

请将以下内容替换为

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

作者:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
    end
  end
end

执行以下命令:

flutter clean 
flutter pub get
cd ios && pod install

现在

  1. 构建项目
  2. 关闭并重新打开Xcode

4
Flutter中的普通用户或新手可能不知道在哪里更改所有这些内容。 - Pratik Butani
1
@PratikButani 在Flutter项目目录中更改此项 ==> ios ==> Podfile - Abhishek Kumar
这个问题与Ionic类似,删除flutter_additional_ios_build_settings(target)行有所帮助。 - Sawyer Herbst
flutter_additional_ios_build_settings的源代码可以在这里找到:https://github.com/flutter/flutter/blob/4f9528293f54037993a6b2eb8f1df5604a3da954/packages/flutter_tools/bin/podhelper.rb。老实说,我认为不应该去修改Podfile。 - DarkNeuron

4

这是因为所有的Pod都没有针对iOS 9.0进行目标设定。

您可以在Podfile中使用以下解决方法:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
        end
    end
end

1
对于Flutter应用程序,在installer.pods_project.targets.each do |target|行之后应添加flutter_additional_ios_build_settings(target) - goldensoju

0

这些警告显然是无害的。以下文档可以在flutter_additional_ios_build_settings()源代码中找到

当pod支持低于Xcode支持的最低版本(Xcode 12 - iOS 9)时,抑制警告。 # 这个警告是无害但令人困惑的——依赖项支持较低版本并不是坏事。

一般来说,我不建议修改Flutter构建环境。你可以从新的Flutter项目中更新它,但除非绝对必要(通常情况下不需要),否则不要在其中放置自定义代码。


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