首页 文章

为CocoaPods的pod设置部署目标

提问于
浏览
29

我使用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:无法合成弱属性,因为当前部署目标不支持弱引用

我已经看到每个库都使用不同的部署目标进行构建 . 例如,使用4.3部署目标构建KeepLayout .

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

3 回答

  • 3

    虽然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
    
  • 68

    由于"pods" project 已设置部署目标,因此您只需要 remove 每个目标的每个部署 target .

    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
    

    灵感来自github post和Alex Nauda的回答 .

  • 0

    1)搜索IPHONEOS_DEPLOYMENT_TARGET

    2)更改iOS部署目标

    enter image description here

相关问题