为 CocoaPods 的 pod 设置部署目标
Set deployment target for CocoaPods's pod
我使用 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: Cannot synthesize weak property because the current deployment target does not support weak references
我看到每个库都是用不同的部署目标构建的。例如 KeepLayout 是用 4.3 部署目标构建的。
我如何确定每个 pod 依赖项的构建目标?
虽然 Cocoa 的某些开发版本Pods(以及 1.0 之前的版本)可能已将项目的部署目标传播到 pods,但这是 no longer the case in 1.0. To work around this, the current developer recommends使用 post-安装挂钩。
这是一种蛮力方法,可以为生成的 Pods 项目中的每个 pod 强制执行硬编码部署目标。将此粘贴到 Podfile
:
的 end
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
因为 Podfile
使用像 platform :ios, '9.0'
这样的指令来为 Pods/Pods.xcodeproj 项目指定“iOS 部署目标”(又名 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 的回答的启发。
1) 搜索 IPHONEOS_DEPLOYMENT_TARGET
2) 更改 iOS 部署目标
将目标更改为“11.0”
platform :ios, '11.0'
虽然 Alex Nauda 接受的答案很好,但让 Pods 从应用程序继承目标可能是更好的解决方案。
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
这里是为 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
我使用 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: Cannot synthesize weak property because the current deployment target does not support weak references
我看到每个库都是用不同的部署目标构建的。例如 KeepLayout 是用 4.3 部署目标构建的。
我如何确定每个 pod 依赖项的构建目标?
虽然 Cocoa 的某些开发版本Pods(以及 1.0 之前的版本)可能已将项目的部署目标传播到 pods,但这是 no longer the case in 1.0. To work around this, the current developer recommends使用 post-安装挂钩。
这是一种蛮力方法,可以为生成的 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
因为 Podfile
使用像 platform :ios, '9.0'
这样的指令来为 Pods/Pods.xcodeproj 项目指定“iOS 部署目标”(又名 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 的回答的启发。
1) 搜索 IPHONEOS_DEPLOYMENT_TARGET
2) 更改 iOS 部署目标
将目标更改为“11.0”
platform :ios, '11.0'
虽然 Alex Nauda 接受的答案很好,但让 Pods 从应用程序继承目标可能是更好的解决方案。
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
这里是为 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