【问题标题】:How to automatically install 3rd party frameworks from Podspec如何从 Podspec 自动安装 3rd 方框架
【发布时间】:2020-02-13 05:57:21
【问题描述】:

我是创建自己的框架的初学者。我能够按照说明创建私有 Pod。我创建了两个存储库,一个用于 Podspecs 存储库,一个用于我尝试制作的 Pod(PodA)。我已经将 PodA 正确推送到 Podspecs 存储库、正确的标记和正确的 Podspecs 文件。

PodA 依赖于公共的 3rd 方框架。 所以,在我的 Podspecs 中,我添加了

s.dependency 'Alamofire', '~> 5.0.0-rc.3'

在 MainApp Podfile 中

source '<Private Pod URL>'

target 'MyAppName' do   

    use_frameworks!    
    pod 'PodA'

end

当我尝试在 MyAppName 目录上调用 pod install 时,出现错误

Unable to find a specification for 'Alamofire (= 5.0.0-rc.3)' depended upon by 'PodA'

提前致谢

编辑: PodA 是我尝试制作的 Pod 的虚拟名称

编辑:添加 Podspecs 文件。更改了摘要、描述和主页

Pod::Spec.new do |s|
  s.name             = 'TestPrivatePod1'
  s.version          = '0.2.2'
  s.summary          = 'Dummy summary.'

  s.description      = <<-DESC
            "Dummy Description."
                       DESC

  s.homepage         = 'http://www.google.com/'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'vicWT' => 'vic@worktable.sg' }
  s.source           = { :git => 'https://github.com/vicWT/TestPrivatePod1.git', :tag => '0.2.2' }

  s.ios.deployment_target = '12.0'


  s.source_files = 'TestPrivatePod1/Classes/**/*'
  s.swift_version = '5'
  s.dependency 'Alamofire', '~> 5.0.0-rc.3'


end

编辑: 删除源“https://github.com/Alamofire/Alamofire.git

编辑:修复从 s.dependency 'Alamofire', '5.0.0-rc.3s.dependency 'Alamofire', '~&gt; 5.0.0-rc.3 的语法错误

编辑:添加 TestPrivatePod1 图像

【问题讨论】:

  • 什么是PodA
  • 这是我尝试制作的 Pod 的名称。对不起,我应该详细说明。将编辑帖子。那只是个假名
  • 不,你能分享一下 pod 的名称吗,我知道这是一个虚拟的 pod 名称,但我需要知道 pod 是什么以及为什么 Alamofire 依赖它,否则它会不工作。
  • 请参阅编辑后的帖子。它包括 Private Pod 的真实名称。 TestPrivatePod1
  • 我已将 repo 公开,如果您想查看该 repo,但问题解决后我会将其恢复为私有

标签: swift xcode cocoapods


【解决方案1】:

试试下面的:

pod repo remove master
pod setup
pod update

同时改变你在 podfile 中的依赖,如下所示。

s.dependency 'Alamofire', '~> 5.0.0-rc.3'

并在您的 mainApp podfile 中指定 platfor 版本:

 platform :ios, '10.3'

如果上述方法不起作用,请运行以下命令重新安装 cocoapod:

rm -rf ~/.cocoapods/repos/master

sudo gem install cocoapods

请在您的项目 TestPrivatePod1 的 podfile 中评论 pod 'Alamofire', '~&gt; 4.9'

【讨论】:

  • 你能分享你的 PodA podspec 文件吗?或者我已经编辑了我的答案,请检查。
  • 编辑帖子以包含 Podspecs 文件
  • 请尝试使用另一个版本'Alamofire','~> 4.9'并检查
  • 同样的错误,[!] Unable to find a specification for `Alamofire (~&gt; 4.9)` depended upon by `TestPrivatePod1` You have either: * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`. * mistyped the name or version. * not added the source repo that hosts the Podspec to your Podfile.
【解决方案2】:

您可以尝试更改用于指定依赖项版本的语法吗?

类似于:

s.dependency 'Alamofire', '~> 5.0.0-rc.3'

注意在指定版本号之前使用的额外符号? Cocoapods 推荐使用乐观版本指示器,即:~&gt;

Reference

如果它仍然不起作用,请告诉我...

【讨论】:

  • 谢谢.. 我错过了.. 我已将其更改为 s.dependency 'Alamofire', '~&gt; 5.0.0-rc.3' 。但错误仍然显示[!] Unable to find a specification for `Alamofire (~&gt; 5.0.0-rc.3)` depended upon by `TestPrivatePod1` You have either: * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`. * mistyped the name or version. * not added the source repo that hosts the Podspec to your Podfile.
  • 好的,这个错误是正常的。你可以试试在终端上做pod repo update吗?
  • 输入pod repo update再输入pod install后,出现同样的错误
  • pod repo updatepod install 成功了吗?我的意思是,您在终端上看到任何错误消息了吗?
【解决方案3】:

您似乎误解了这一切是如何运作的。 Cocoapods 从规范 repo 中获取 pod 的定义,这是 Podfile 中的source,它不是单个 pod 的存储库。默认的规范 repo 是 https://github.com/CocoaPods/Specs.git,如果您希望能够使用任何公共 pod,例如 Alamofire,则需要将其添加到您的 Podfile。

将您的私有存储库添加为 URL 没有意义,因为它不是包含多个规范的存储库,它只是一个 pod 的存储库。

我认为这样的事情可能会奏效:

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

target 'MyAppName' do   

    use_frameworks!    
    pod 'PodA', :git => '<Private Pod URL>'

end

如果没有,那么您必须创建自己的规范存储库,其中包含您的 pod 的定义。我就不说了,but there are a lot of resources about that.

【讨论】:

  • 你的意思是这样的吗? source 'https://github.com/vicWT/PodSpecsRepoPrivate.git'
  • 不,添加默认的 pod 规范仓库以及您自己的私有仓库。您可以拥有多个 repo。
  • 对不起,我不明白,默认的 pod 规范是什么意思?和私人的?我的理解是“私人”是TestPrivatePod1,默认的pod规范是TestPrivatePod1.podspec,这是正确的吗?请看上面的图片
  • 当我添加 source 'https://github.com/CocoaPods/Specs.gitpod 'TestPrivatePod1', :git =&gt; 'https://github.com/vicWT/PodSpecsRepoPrivate.git' ,然后 pod install 时,它似乎只是在加载,我不得不终止终端..
猜你喜欢
  • 2023-03-25
  • 1970-01-01
  • 2021-12-23
  • 1970-01-01
  • 2020-07-14
  • 2020-01-19
  • 1970-01-01
  • 1970-01-01
  • 2022-01-21
相关资源
最近更新 更多