为 CocoaPods 的吊舱设定部署目标

我使用 CocoaPods 来管理项目中的依赖关系:

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

我不能错误地编译我的项目:

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

我看到每个库都是用不同的部署目标构建的,例如 KeepLayout 就是用4.3部署目标构建的。

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

67914 次浏览

While some development versions of CocoaPods (as well as pre-1.0 versions) may have propagated the deployment target of the project down to the pods, this is no longer the case in 1.0. To work around this, the current developer recommends using a post-install hook.

Here's a brute force approach to force a hard-coded deployment target for every pod in the generated Pods project. Paste this at the end of your 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

Since the Podfile uses a directive like platform :ios, '9.0' to specify "iOS Deployment Target" (aka IPHONEOS_DEPLOYMENT_TARGET) for the Pods/Pods.xcodeproj project, you just need to remove the Deployment Target info from each build target.
Do it by adding this to your 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

Inspired by the github post and Alex Nauda's answer.

1) Search for IPHONEOS_DEPLOYMENT_TARGET

2) Change the iOS Deployment Target

enter image description here

change target to "11.0"

platform :ios, '11.0'

While the accepted answer by Alex Nauda is good, but letting the Pods inherit the target from the app might be a much better solution. 🚀

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

Here is the way to set deployment target permanently for pod targets.

Goto -> podfile -> Add below code

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