ios - Cocoapods:Podfile 通过具有相同名称但不同来源的两个 pod 发生冲突

标签 ios cocoapods podspec podfile

我有自己的带有内部 pod 的私有(private)规范存储库。我曾经为 pod 添加前缀,但现在我正在迁移到 Swift,我想摆脱它们。

但是,如果我去掉前缀(例如 JAMNetworking 到 Networking)并在 Podfile 中指定两个源,我就会遇到冲突,因为 Networking 是来自主存储库的现有公共(public) pod。我知道一个可能的解决方案是在每个 pod 旁边指定 git 存储库 url,但是为每个 pod 添加 url 对我来说很烦人,所以我正在寻找一个优雅的解决方案。我有一些想法,但似乎都没有用:

A) 为source添加名称,为每个pod指定source名称,例如

source 'master', 'https://github.com/CocoaPods/Specs.git'
source 'internal', 'https://myurl.git'

pod 'samePodName', 'master'
pod 'samePodName', 'internal'

B) 使用内部指定的源创建两个定义:

def publicPods
    source 'master', 'https://github.com/CocoaPods/Specs.git'
    pod 'samePodName'
end

def internalPods
    source 'internal', 'https://myurl.git'
    pod 'samePodName'
end

target 'MyProject' do
    publicPods
    internalPods
end

不幸的是,这只会将其中一个 def 视为有效而忽略另一个...因此在这种情况下,它将安装公共(public) def。如果我在安装后切换然后卸载公共(public)的并安装内部的。

C) 创建多个目标。它返回有关具有相同名称的多个目标的错误。

您认为是否可以找到一个优雅的解决方案,而无需为每个 pod 添加 url 或避免添加前缀?

最佳答案

目前最好的解决方案是保留您的前缀。考虑

a) 人们普遍认为,最佳做法是让您的 pod 与其公开的 Swift 模块同名

b) Swift 模块不能链接到另一个具有重名的模块

... 这使得如何管理重复的 pod 名称的问题变得没有实际意义。

埃里卡·萨顿 came to the same conclusion here .直到其中提出的反向 DNS 标识符之类的东西成为现实,

Package names need to be clear and specific, yes, but they should avoid terms that will overlap because when you have a package called SwiftString and every Bob, Jane, and Harry also has a package called SwiftString, name collisions are inevitable...

And, until then, prefer SadunSwiftString to SwiftString and avoid the issue from the start.

坚持使用前缀,因为这里真正的问题是 Swift 缺少模块级别以上的命名空间。到解决这个问题时,毫无疑问,我们都将使用 SPM!

关于ios - Cocoapods:Podfile 通过具有相同名称但不同来源的两个 pod 发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38118937/

相关文章:

php - API安全问题

ios - 关闭 UIPickerView

ios - 我们如何在自定义表格单元格中实现具有动态内容的动态项目?

ios - 操作系统 pod 安装错误。无法安装模块 glog

ios - 具有相关 Objective-C Pod 的 Swift Pod 的桥接头?

iOS SDK Interface Builder 的 RGB slider 产生与 UIColor withRGB 不同的颜色

ios - Pod 规范验证 Cocoa Pod 问题

objective-c - 如何创建包含静态库的 pod?

ios - Cocoapods 未正确链接私有(private)框架 Pod

ios - 当 pod lib lint 成功时,pod spec lint 失败。 'vendored_frameworks' 模式不匹配任何文件