为CocoaPods的pod设置部署目标

And*_*nov 43 xcode ios cocoapods xcode7

我使用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
Run Code Online (Sandbox Code Playgroud)

这个文件适用于CocoaPods 0.x,但是在我更新到CocoaPods 1.0后我无法编译项目.我跑完之后

pod update 
Run Code Online (Sandbox Code Playgroud)

我无法编译我的项目错误:

/Users/<...>/Pods/KeepLayout/Sources/KeepAttribute.m:195:1:无法合成弱属性,因为当前部署目标不支持弱引用

我已经看到每个库都使用不同的部署目标进行构建.例如,使用4.3部署目标构建KeepLayout.

我如何确定每个pod依赖项的构建目标?

Ale*_*uda 97

虽然CocoaPods的一些开发版本(以及1.0之前的版本)可能已将项目的部署目标传播到pod,但1.0中不再是这种情况.要解决此问题,当前的开发人员建议使用安装后挂钩.

这是一种强制方法,用于强制生成的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
Run Code Online (Sandbox Code Playgroud)

  • 将“9.2”替换为您想使用的任何部署目标。 (3认同)
  • MACOSX_DEPLOYMENT_TARGET (3认同)
  • 为什么不从每个目标设置中删除密钥“IPHONEOS_DEPLOYMENT_TARGET”?项目已经设置了它的部署目标,每个目标只是继承它。 (3认同)
  • 我们已经更新了库的规格,但您的解决方案很棒. (2认同)
  • macOS 的设置是什么? (2认同)

Yan*_*eez 23

以下是为 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
Run Code Online (Sandbox Code Playgroud)


Daw*_*ong 22

因为"荚" 项目已设置部署目标,你只需要删除部署目标每个构建的目标.将此附加到您的结尾Podfile

post_install do |lib|
    lib.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
        end
    end
end
Run Code Online (Sandbox Code Playgroud)

灵感来自github帖子和Alex Nauda的答案.

  • 是的-与重复您的部署目标相比,删除特定设置并使用默认设置似乎是一种更简洁的解决方案(这是另外一件出错的事情)。 (3认同)
  • 我找到了 - Podfile 似乎是项目中名为“Podfile”的文件 (2认同)
  • 这应该是公认的答案。谢谢你! (2认同)

Ahm*_*san 12

虽然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
Run Code Online (Sandbox Code Playgroud)


Sha*_*med 7

Swift 5 简单解决方案将以下代码复制粘贴到 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
Run Code Online (Sandbox Code Playgroud)

安装你的 Pod

//MARK: - Run the command in your terminal
pod install
Run Code Online (Sandbox Code Playgroud)

快乐编码


Fra*_*sco 5

1)搜索IPHONEOS_DEPLOYMENT_TARGET

2)更改iOS部署目标

在此处输入图片说明

  • 这不是一个长期的解决方案。“ pod安装”会将设置恢复为podspec中的设置。 (3认同)