我正在编写一个 iOS 库,它使用 Restkit 等外部库。在我的库中一切正常,但当我使用 Pod 将其导入其他项目时,只导入了我的源代码。这意味着我没有像 Restkit 这样的外部依赖项。
我在 podspec 文件中添加了:s.dependency 'Restkit' '~> 0.24.0'
但我看不出有什么不同。我觉得我错过了什么,有人可以帮助我吗?
问候
编辑
SDK podspec 文件(重要部分):
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.source = { :git => "***************.git", :tag => "0.0.1" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.source_files = "bee-ios-sdk/sdk", "bee-ios-sdk/sdk/**/*.{h,m}"
s.exclude_files = "bee-ios-sdk/sdk/Exclude"
# s.public_header_files = "Classes/**/*.h" # Maybe this ?
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
# s.requires_arc = true
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
s.dependency 'RestKit', '~> 0.24.0'
s.dependency 'CocoaSecurity'
还有我的应用程序中的 Podfile
target 'bee' do
pod 'bee-ios-sdk' # Private pod repository containing the podspec above
end
希望对你有帮助
编辑 2
$ pod install
Analyzing dependencies
Downloading dependencies
Installing bee-ios-sdk (0.0.1)
Generating Pods project
Integrating client project
如您所见,我只有我的来源。当我尝试构建时,没有发现 RestKit 和其他导致我出现“RestKit/RestKit.h”文件未找到错误的痕迹。在我的应用程序 podfile 中添加我所有的 SDK 依赖项可以解决问题,但这显然不是很性感..
我的 podfile 顶部没有源“github.com/CocoaPods/Specs.git”? 现在,我的 podfile (app) 请求一个私有(private)的 git repo,其中包含 .podspec 文件,其中包含我的 sdk 的 url。我跟着这个tutorial去做。
最佳答案
我已经使用 Cocoapods 构建了几个内部库,虽然我无法立即准确理解为什么您无法获得正确的依赖关系,但我认为概述我是如何做到的可能是个好主意。
总的来说,典型的安装(从头开始)有以下步骤:
- 将 cocopods 安装到您的机器上(
sudo gem install cocoapods
) - 设置一个私有(private)存储库来存放您所有的 cocoapods。
- 创建新的 pod 规范
- 运行 linter,然后将您的规范推送到存储库
第 1 步很简单,让我们从第 2 步开始:
设置一个私有(private)仓库来存放你所有的 cocoapods
您应该可以推送访问将存放您的 pod 的 git 位置。一旦设置了这个 repo,你就可以将它添加到你的安装中:
pod repo add internalpods 'github.com/private-cocoapodsspecs.git'
当然我输入了一个伪造的 git url
创建您的第一个规范
创建规范很容易:
pod spec create SPEC_NAME
SPEC_NAME 是您希望规范的名称
我不会在这里详细介绍,因为您的规范对我来说似乎不错。但是,我尝试做的总是将一个示例项目放在您检查规范的存储库中。 cocoapods 的一大特点是您可以在本地引用规范。假设我们编写 AFNetworking,git 中的文件结构可能如下所示:
AFNetworking
.git
AFNetworking.podspec
AFNetworking/
(All the classes we want in our pods)
ExampleProject/
(Example project that will use the spec locally)
podfile
在示例项目的 podfile 中,我们可以这样做:
source 'https://github.com/CocoaPods/Specs.git' #include this if you will be referencing any public pods!
source 'github.com/private-cocoapodsspecs.git' #our internal repo which we don't need yet
pod 'AFNetworking', :path => '..'
这让您可以在运行任何安装或推送到您的服务器之前确定您的 pod 是否存在任何问题,所以我非常喜欢这种方法。它还允许您开发您的 pod 并拥有一个很好的示例项目,您可以随时打开该项目以对您的 pod 进行更改或测试新功能。
在您的示例项目中运行 pod install
应该可以让您启动并运行您的 pod 和所有依赖项。不要忘记您始终可以将 --verbose
添加到安装中。
现在是时候将您的好意发送到 Remote 了:
lint 和推送
linter 将验证您的规范以确保它已准备好推送(请注意我如何包含我们内部远程的源 url):
pod spec lint --sources=github.com/private-cocoapodsspecs.git,https://github.com/CocoaPods/Specs.git --verbose
如果一切顺利,您可以继续推进。我通常喜欢在执行此操作时允许警告,因为我们的内部 pod 没有许可证,如果您尝试在没有许可证的情况下推送,一切都会崩溃:
pod repo push internalpods SPEC_NAME.podspec --allow-warnings --verbose
看看我如何使用我们在第 1 步中设置的 internalpods 名称。
希望这足以对您有所帮助。
关于iOS 内部 podspec 安装不安装外部 Pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27900365/