ChatGPT解决这个技术问题 Extra ChatGPT

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

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

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

临时解决方案:进入xcode,点击'Pods'项目,将部署目标设置为6以上,我想,当'weak'出现时。我有8.0。但是在每个 pod 安装后,它都会恢复为 4,所以我也对最终解决方案感到好奇。
谢谢。我以前创建过它,但不要认为它是一个好的解决方案。
我还找到了为项目中的每个目标自动创建它的脚本,但它不适用于 CocoaPods 1.0。 :(
pod update 将 pod 的部署目标设置为 iOS 4.3,因为如果 podspec 未指定,这是默认部署目标。这是 CocoaPods 团队有意做出的决定,尽管它破坏了一些基本上具有不完整 podspec 的旧 pod。如果您正在维护 pod,则应指定适当的目标,例如 platform :ios, '8.0' 来修复它。如果您只是想使用以这种方式损坏的 pod,请尝试以下我的建议。
@codrut 感谢您的快速修复。对于其他人来说,我刚刚更新到 Cocoapods 1.0.0。这需要在我的 podfile 中更改语法。我正在使用可能 15 个 pod,除了 MBProgressHUD 之外,它们都编译得很好。正如我的 Podfile 中定义的那样,Pods 项目本身设置为 8.0,但由于某种原因,MBProgressHUD 目标设置为 4.3。 Alex Nauda 列出的修复程序非常适合永久解决方案。

D
DawnSong

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

'9.2' 替换为您想要使用的任何部署目标。
我们更新了库的规格,但您的解决方案很棒。
macOS 的设置是什么?
MACOSX_DEPLOYMENT_TARGET
为什么不从每个目标设置中删除密钥 IPHONEOS_DEPLOYMENT_TARGET?项目已经设置了它的部署目标,每个目标都只是继承它。
D
DawnSong

由于 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 回答的启发。


@bluebamboo 将其附加到您的 Podfile
是的 - 删除特定设置并使用默认设置似乎比重复部署目标更简洁(只是另一件事出错)。
我如何找到这个 podfile?
我找到了 - Podfile 似乎是项目中名为“Podfile”的文件
这应该是公认的答案。谢谢!
A
Ahmed M. Hassan

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

Y
Yano

这是为 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


A
As If Prince

将目标更改为“11.0”

platform :ios, '11.0'

F
Francesco

1) 搜索 IPHONEOS_DEPLOYMENT_TARGET

2) 更改 iOS 部署目标

https://i.stack.imgur.com/8nNOI.png


这不是一个长期的解决方案。 “pod install”会将设置恢复为 podspec 中的设置。

关注公众号,不定期副业成功案例分享
关注公众号

不定期副业成功案例分享

领先一步获取最新的外包任务吗?

立即订阅