xcode 为CocoaPods的Pod设置部署目标

mrzz3bfm  于 2023-05-08  发布在  其他
关注(0)|答案(7)|浏览(208)

我使用CocoaPods来管理项目中的依赖项。我写了一个Podfile:

target 'MyApp' do
  platform :ios, '8.0'
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  #use_frameworks!

  # Pods for MyApp
  pod 'KeepLayout', :git => 'https://github.com/iMartinKiss/KeepLayout', :tag => 'v1.6.0'
  pod 'EasyMapping'

  target 'MyAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MyAppUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

这个文件在CocoaPods 0.x下运行的很好,但是在我更新到CocoaPods 1.0后,我无法编译项目。在我跑完之后

pod update

我无法编译我的项目,出现错误:
/Users/<...>/Pods/KeepLayout/Sources/KeepAttribute.m:195:1:无法合成弱属性,因为当前部署目标不支持弱引用
我看到每个库都是用不同的部署目标构建的。例如,KeepLayout是使用4.3部署目标构建的。
如何确定每个pod依赖项的构建目标?

yh2wf1be

yh2wf1be1#

虽然CocoaPods的一些开发版本(以及1.0之前的版本)可能已经将项目的部署目标传播到pod,但这是no longer the case in 1.0。要解决这个问题,the current developer recommends使用安装后钩子。
这里有一个强力方法,可以为生成的Pods项目中的每个Pod强制一个硬编码的部署目标。将其粘贴到Podfile的***末尾***:

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

iezvtpos2#

由于Podfile使用类似platform :ios, '9.0'的指令为Pods/Pods.xcodeproj项目指定“iOS Deployment Target”(又名IPHONEOS_DEPLOYMENT_TARGET),因此您只需从每个构建目标中删除******************************************************************************************************************************************************************************************
通过将其添加到您的Podfile来完成此操作

platform :ios, '9.0' # set IPHONEOS_DEPLOYMENT_TARGET for the pods project
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

灵感来自github post和Alex Nauda的答案。

chhqkbe1

chhqkbe13#

为Pod目标永久设置部署目标的方法如下:
后藤-> podfile ->添加下面的代码

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

ymdaylpp4#

虽然 Alex Nauda 的公认答案是好的,但让Pod从应用程序继承目标可能是一个更好的解决方案。🚀

app_ios_deployment_target = Gem::Version.new('9.2') # Change to your current deployment target

platform :ios, app_ios_deployment_target.version

# Let Pods targets inherit deployment target from the app
# This solution is suggested here: https://github.com/CocoaPods/CocoaPods/issues/4859
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |configuration|
      pod_ios_deployment_target = Gem::Version.new(configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
      if pod_ios_deployment_target <= app_ios_deployment_target
        configuration.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      end
    end
  end
end
flmtquvp

flmtquvp5#

将目标更改为“11.0”

platform :ios, '11.0'
vd2z7a6w

vd2z7a6w6#

Swift 5 Simple Solution将下面的代码复制粘贴到你的podFile中

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.1' //set your minimum version your all pods will set to mininum 13.1 version :-)
    end
  end
end

安装您的pod

//MARK: - Run the command in your terminal
pod install

快乐编程

j13ufse2

j13ufse27#

1)搜索IPHONEOS_部署_目标
2)更改iOS部署目标

相关问题