我使用 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 依赖项的构建目标?
pod update
将 pod 的部署目标设置为 iOS 4.3,因为如果 podspec 未指定,这是默认部署目标。这是 CocoaPods 团队有意做出的决定,尽管它破坏了一些基本上具有不完整 podspec 的旧 pod。如果您正在维护 pod,则应指定适当的目标,例如 platform :ios, '8.0'
来修复它。如果您只是想使用以这种方式损坏的 pod,请尝试以下我的建议。
虽然 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
由于 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 回答的启发。
Podfile
虽然 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
这是为 pod 目标永久设置部署目标的方法。
转到 -> podfile -> 添加以下代码
post_install 做 |安装程序| installer.pods_project.targets.each 做 |target| target.build_configurations.each 做 |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "12.0" end end end
将目标更改为“11.0”
platform :ios, '11.0'
1) 搜索 IPHONEOS_DEPLOYMENT_TARGET
2) 更改 iOS 部署目标
https://i.stack.imgur.com/8nNOI.png
'9.2'
替换为您想要使用的任何部署目标。IPHONEOS_DEPLOYMENT_TARGET
?项目已经设置了它的部署目标,每个目标都只是继承它。