我使用 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 依赖项的构建目标?
虽然 CocoaPods 的某些开发版本(以及 1.0 之前的版本)可能已将项目的部署目标传播到 pod,但 1.0 中不再是这种情况。要解决此问题,当前开发人员建议使用安装后挂钩。
这是一种蛮力方法,可以为生成的 Pod 项目中的每个 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
),你只需要remove每个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 帖子 和 Alex Nauda 的回答。
这里是为 Pod 目标永久设置部署目标的方法。
Goto -> 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
虽然 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
斯威夫特 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
安装你的豆荚
//MARK: - Run the command in your terminal
pod install
快乐编码
将目标更改为“11.0”
platform :ios, '11.0'