阻止 "There are multiple dependencies with different sources" 使用 CocoaPods

Prevent "There are multiple dependencies with different sources" using CocoaPods

我在几个项目中结合使用了自己的和外部的 pods。如果我正在开发或更新 pod,我会使用 Podfile.local 来避免 versioning/tagging 每次更改。这里的问题,如果我必须更新 Podfile 以注释掉我在 Podfile.local 中使用的每个 pod 以避免错误。

有什么方法可以告诉 cocoapods 当两个文件具有相同的 pod 时应该考虑 Podfile.local 而不是 Podfile 以防止出现此错误:

Analyzing dependencies [!] There are multiple dependencies with different sources for Analytics in Podfile:

  • Analytics (HEAD)
  • Analytics (from ~/Documents/analytics_ios)

我的播客文件:

source 'https://github.com/CocoaPods/Specs.git'
source 'http://gitlab.whatever.com/podfolder/cocoapods_ios.git'
platform :ios, '7.0'

# Allows per-dev overrides
local_podfile = "Podfile.local"
eval(File.open(local_podfile).read) if File.exist? local_podfile

pod 'Advertising/Dfp', :head
pod 'RSSParser', :head
pod 'DTCoreText'
pod "AFNetworking", "~> 2.0"
pod 'OurKeyboard', :head
pod 'VideoPlayer/GooglePrerollForAdMob', :head
pod 'Analytics', :head
pod 'AppVersioning', :head

我的Podfile.local:

pod 'Analytics', :path => '~/Documents/analytics_ios'

自 CocoaPods 0.35 以来,Podfile.local 技巧不再可行,并且从未得到官方支持。
参见 https://github.com/CocoaPods/CocoaPods/issues/2860

在配置的现有应用程序中的 Watch 扩展 中安装 pod 时也会出现同样的问题:- Swift-3,Xcode -8.1 和 Pod 版本 1.0.1.

存在上述错误的 Podfile :

platform :ios, ‘10.0’ source 'https://github.com/CocoaPods/Specs.git' 
use_frameworks!

target "DemoApp" do
        pod 'SwiftQRCode'
        pod 'Alamofire'


post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '3'
      end
    end  
end

target 'WatchExtension' do 
platform :watchos, '2.0'
pod 'Alamofire' 
pod 'SwiftyJSON' 
end

pod install

解决方案:

创建可在主应用程序包和 watch OS 扩展之间共享的共享定义:-

Updated podfile : source 'https://github.com/CocoaPods/Specs.git'   

#Create common defination to share the library between app and extension

def shared_pods    
pod'Alamofire'   
pod 'SwiftyJSON'  
end

target "DemoApp" do
        platform :ios, '10.0'
        use_frameworks!
        shared_pods

   post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '3'
        end
      end  
 end

target 'WatchExtension' do 
     platform :watchos, '2.0'
     use_frameworks!
     shared_pods
end

因此,更改 podfile 已解决上述问题“具有不同来源的多个依赖项....”。

需要更新库搜索路径:-

我的问题是我有两个相同的包。一个已弃用,另一个是我刚刚安装的新包,但我没有卸载已弃用的软件包。因此,新包向我的 Podfile 添加了一个依赖项,而已弃用的包添加了相同的依赖项,但来自不同的来源。我想卸载已弃用的软件包,错误消失了。