首页 > 解决方案 > 找不到具有传递依赖的开发 pod

问题描述

我正在开发一个 iOS 项目,在同一个 git 存储库中包含多个 pod,并且在使用development pods时我无法使用传递依赖项。

想象一下,我有以下存储库结构。

Root folder
   - iOS # App folder
   - modules
       - ModuleA
       - ModuleB

iOS 应用文件夹、模块 A 和模块 B 包含配置了 cocoapods 的 iOS 项目。它们都带有一个 Podfile 和一个配置为使用本地依赖项的 podspec。iOS 应用程序依赖于模块 A,模块 A 依赖于模块 B。但是,当我从 iOS 应用程序文件夹运行 pod install 时,它找不到 ModuleB 依赖项,并强制我手动将 ModuleB 依赖项声明为 iOS 应用程序 podfile 的一部分. 即使 ModuleA 依赖项已经在前 1 行声明并且 ModuleB 是 ModuleA 的依赖项。

这是配置 podfile 的方式:

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

platform :ios, '9.0'
inhibit_all_warnings!

target 'iOS' do
  pod 'ModuleA', :path => 'modules/ModuleA/'
  # ModuleB pod should be imported as a transitive dependency of ModuleA 
  # but if I don't add it explicitly whenever I execute pod install, 
  # cocoapods fails because it can't find ModuleB.
  pod 'ModuleB', :path => 'modules/ModuleB/' 
  target 'iOSTests' do
    inherit! :search_paths
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    puts target.name
  end
end
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '9.0'
inhibit_all_warnings!

target 'ModuleA' do
  pod 'ModuleB', :path => '../ModuleB/'
  target 'ModuleATests' do
    inherit! :search_paths
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    puts target.name
  end
end
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '9.0'
inhibit_all_warnings!

target 'ModuleB' do
  target 'ModuleBTests' do
    inherit! :search_paths
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    puts target.name
  end
end

这是我们的 podspec 的配置方式:

Pod::Spec.new do |s|
  s.name         = "ModuleA"
  s.version      = "1"
  s.summary      = "ModuleA"
  s.homepage     = "https://github.com/pedrovgs/iOSApp"
  s.license      = "MIT"
  s.author       = { "Pedro" => "pedro@pedro.com" }
  # This path param is not available since cocoapods 16
  s.source       = { :path => '.' } 
  s.module_name  = 'ModuleA'
  s.requires_arc = true

  s.source_files = '/**/*.swift'

  s.ios.deployment_target = '12.0'
  
  s.dependency 'ModuleB'

  s.swift_version = '5.0'
end

Pod::Spec.new do |s|
  s.name         = "ModuleB"
  s.version      = "1"
  s.summary      = "ModuleB"
  s.homepage     = "https://github.com/pedrovgs/iOSApp"
  s.license      = "MIT"
  s.author       = { "Pedro" => "pedro@pedro.com" }
  # This path param is not available since cocoapods 16
  s.source       = { :path => '.' } 
  s.module_name  = 'ModuleB'
  s.requires_arc = true

  s.source_files = '/**/*.swift'

  s.ios.deployment_target = '12.0'

  s.swift_version = '5.0'
end

pod install从 iOS 文件夹执行时,我面临的错误问题可以重现。ModuleB除非我明确声明它在哪里,否则Cocoapods 无法从 iOS 项目中找到pod pod 'ModuleB', :path => 'modules/ModuleB/':. 如果你看一下 podspecs,这是有道理的。未s.source正确配置,因为:path不再支持 param。我可以配置一个 git 存储库或一个指向 zip 文件的 HTTP url,正如2019 年 GitHub 上的这条评论所建议的那样,但我想知道是否缺少任何配置。我发现的另一个选择迫使我将所有 podspecs 声明为根文件夹的一部分,就像Firebase iOS SDK 所做的那样。

这个问题迫使我在所有使用 ModuleA 的 pod 中将 ModuleB 指定为传递依赖项,除非我让 podspecs 配置正常工作。没有其他解决办法吗?我想将我的 pod 保存在不同的文件夹中,并将 podspec 文件放置在 Podfile 附近。我正在工作的存储库包含与不同平台相关的代码,因此我想避免将 podspecs 添加到 GitHub 问题中提到的根文件夹中。

关于 podspec。该命令pod lib lint --no-clean --allow-warnings失败,因为它指定ModuleB找不到 pod。这很明显,因为s.source配置无效。Cocoapods 不会崩溃,它只会显示一个警告,但是当我们尝试验证 podspec 时会失败。

标签: iosswiftcocoapods

解决方案


推荐阅读