iOS模拟器的部署目标设置为7.0,但该平台支持的部署目标版本范围为8.0至12.1。

354

我在Xcode 10.1中收到以下警告信息:

iOS模拟器部署目标设置为7.0,但此平台支持的部署目标版本范围为8.0到12.1。

我的模拟器系统为12.1, Xcode 10.1, 并已更新pod文件。

输入图像说明

我的部署目标为9.0

输入图像说明

在我的目标中

输入图像说明


请在 https://user-images.githubusercontent.com/5786033/45890297-f23a1d00-bdc2-11e8-885c-039432d8fbc2.png 中验证目标,请注意:该操作在框架中进行。 - Vinaykrishnan
@ Vinaykrishnan,我检查了,它是9.0。 - Naresh
5
这位朋友遇到了同样的问题,检查一下这些链接或许可以帮到你:https://github.com/flutter/flutter/issues/22123 和 https://github.com/CocoaPods/CocoaPods/issues/8069。打开你的 Xcode,在苹果图标的左上方找到 File,然后打开 Workspace Settings 并将构建系统更改为 Legacy Build System。如果你还没有尝试过这个方法,可以查看这个网址的答案:https://dev59.com/oVQK5IYBdhLWcg3wDLvP#52552878 - Vinaykrishnan
29个回答

517

您可以这样设置podfile以自动匹配所有podfiles的部署目标与当前项目部署目标:

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

15
如果您已经有另一个安装后钩子,将会出现错误提示表明不支持多个安装后钩子。请问您需要怎样处理? - George Salamanca
5
@GeorgeSalamanca,你可以将它放到同一个post_install块中。 - Simon Hansen
14
@Fattie 我相信你只需要执行 config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' 即可。 - rmp251
4
我已经在podfile中插入了代码片段,但它没有起作用。 - StackGU
7
你好@Tao-Nhan Nguyen,这段代码应该添加在哪里?谢谢。 - Miguel Espeso
显示剩余14条评论

131
问题在于您的Pod文件部署目标iOS版本,而不是项目部署目标iOS版本,因此您需要将Pod的部署iOS版本更改为8.0以上的任何版本。要这样做,请打开项目工作区并执行以下操作: 1. 点击Pods。 2. 选择每个项目和目标,然后单击构建设置。 3. 在部署部分中,将iOS部署目标版本更改为任何高于8.0的版本(最好尝试相同的项目版本)。 4. 对于您的Pod中的每个其他项目,请重复此过程,然后运行应用程序。 有关详细信息,请参见此图片: enter image description here

115
Pods 项目是自动生成的。您不应该对其进行更改。 - Mihai Damian
2
我没有对pod进行任何更改(虽然我发现这样做没有问题,因为它是由人类制作的..),我只是更改了应该被定位的iOS版本,这是可以接受的。而且这比强制降低你自己项目的iOS版本的已接受解决方案更好。 - Ahmed El-Bermawy
11
我并不是说采用的解决方案更好,只是编辑生成的文件是不好的做法。任何由Cocoapods生成的文件都不应该手动编辑,因为它们可能会在未来被覆盖。如果你不喜欢输出结果,可以通过post_install从Podfile进行调整。这些文件甚至不应该提交到你的repo上。 - Mihai Damian
1
@Muhammad 这个问题必须由POD开发人员自己回答,但对于我来说,我不会在发布项目时留下任何警告。 - Ahmed El-Bermawy
2
你可以一次性选择它们并进行批量更改。 - Rami Alloush
显示剩余5条评论

120

不要在 pod post install 中指定部署目标,而是删除每个 pod 的部署目标,这会导致从 Podfile 继承部署目标。

您可能需要运行 pod install 以使其生效。

platform :ios, '12.0'

  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

4
如果使用此解决方案的任何人遇到“致命错误:未找到'Flutter / Flutter.h'文件”,则可以尝试在“installer.pods_project.targets.each do |target|”下添加此行:“flutter_additional_ios_build_settings(target)”。 - Nathan Tew
如果您删除了Pod的部署目标,那么在Pod具有比Pod项目更高的部署目标的情况下会发生什么?例如,如果应用程序具有iOS 12的部署目标,并且Podfile指定了iOS 12,以便Pods项目具有iOS 12的部署目标,但其中一个Pod具有iOS 13的部署目标,而我们刚刚清除了该部署目标。应用程序是否会尝试构建Pod并为具有iOS 13部署目标的Pod生成错误? - tjpaul

65

在遍历Tao-Nhan Nguyen所回答的内容时,考虑每个Pod的原始值集合,仅当其小于8.0时进行调整... 将以下内容添加到Podfile中:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if Gem::Version.new('8.0') > Gem::Version.new(config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '8.0'
      end
    end
  end
end

1
这个修复了新创建的React Native应用程序中数百个Xcode警告。 - baskInEminence
这对我很有用,因为最新的Flutter升级中,iOS 10是Xcode 13.3的最低目标。只需要将8.0更改为10.0即可。 - Matthew Rideout

23
我们可以将项目部署目标应用于所有Pod目标。 通过在Podfile末尾添加以下代码块来解决:
post_install do |installer|
  fix_deployment_target(installer)
end

def fix_deployment_target(installer)
  return if !installer
  project = installer.pods_project
  project_deployment_target = project.build_configurations.first.build_settings['IPHONEOS_DEPLOYMENT_TARGET']

  puts "Make sure all pods deployment target is #{project_deployment_target.green}"
  project.targets.each do |target|
    puts "  #{target.name}".blue
    target.build_configurations.each do |config|
      old_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
      new_target = project_deployment_target
      next if old_target == new_target
      puts "    #{config.name}: #{old_target.yellow} -> #{new_target.green}"
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = new_target
    end
  end
end

结果日志:

修复Pods部署目标版本警告


2
不错!有颜色的日志非常有用。 - Asaf Pinhassi

21

如果有人从React Native的问题出发,请删除/build文件夹并输入react-native run ios


2
这个 /build 文件夹在哪里,同事? - Erik Escobedo
3
这是一个路径,表示iOS项目的构建文件夹。 - shogitai
3
那个目录对我来说不存在,但我刚刚运行了 cd ios && pod install && cd ..,然后它又恢复正常了。 - Jimbali

9
尝试以下步骤:
  1. 删除 Podfile.lock 文件
  2. 删除 Podfile 文件
  3. 构建项目
  4. 添加来自 Firebase 的初始化代码
  5. cd /ios
  6. pod install
  7. 运行项目
这是我所做的有效方法。

9

我用这个方法解决了Flutter的问题。打开{your_project_root_folder}/ios/Podfile文件并用以下代码替换post_install块:

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.delete 'IPHONEOS_DEPLOYMENT_TARGET'
    end
  end
end

8

针对Swift语言

如果你正在使用Xcode 12和CocoaPods,那么你可能会遇到下面的错误:

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.

这是因为不再支持iOS 8,但Pod的最低部署目标仍是iOS 8。
在修复之前,您可以将以下内容添加到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

这将从您项目中的所有Pod中删除部署目标,并允许它们继承在Podfile顶部指定的项目/工作区部署目标。

对于React Native

删除./project-root/ios/build文件夹,然后输入react-native run ios

对于Cordova

<preference name="deployment-target" value="8.0" />

7
如果有人在更新到最新的React Native时遇到问题,请尝试更新您的pod文件,使用以下命令:
  use_flipper!
  post_install do |installer|
    flipper_post_install(installer)
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      end
    end
   end

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