ios 为 CocoaPods 的 pod 设置部署目标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37160688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set deployment target for CocoaPods's pod
提问by Andrew Romanov
I use CocoaPods to manage dependencies in my project. I've written Podfile:
我使用 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
This file works well with CocoaPods 0.x but I can't compile project after I've updated to CocoaPods 1.0. After I've run
该文件适用于 CocoaPods 0.x,但在我更新到 CocoaPods 1.0 后无法编译项目。我跑完之后
pod update
I can't compile my project with error:
我无法编译我的项目并出现错误:
/Users/<...>/Pods/KeepLayout/Sources/KeepAttribute.m:195:1: Cannot synthesize weak property because the current deployment target does not support weak references
/Users/<...>/Pods/KeepLayout/Sources/KeepAttribute.m:195:1: 无法合成弱属性,因为当前部署目标不支持弱引用
I've seen that every library is builded with different deployment target. For example KeepLayout is builded with 4.3 deployment target.
我已经看到每个库都是用不同的部署目标构建的。例如 KeepLayout 是使用 4.3 部署目标构建的。
How I can determine build target for every pod dependency?
如何确定每个 pod 依赖项的构建目标?
回答by Alex Nauda
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 recommendsusing a post-install hook.
虽然 CocoaPods 的一些开发版本(以及 1.0 之前的版本)可能已将项目的部署目标向下传播到 pod,但1.0 不再是这种情况。要解决此问题,当前开发人员建议使用安装后挂钩。
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 endof your Podfile
:
这是一种强力方法,可以为生成的 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
回答by DawnSong
Since the "pods" projecthas set deployment target, you just need to removethe deployment targetof each build target. Append this at the endof your Podfile
因为“荚”项目有一系列的部署目标,你只需要删除部署目标每个构建的目标。将此附加在您的末尾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
Inspired by the github postand Alex Nauda's answer.
受github 帖子和 Alex Nauda 的回答启发。