[英]Cocoapods - Create pod for a private iOS repository
I have a repo with code which I do not want to share with others.我有一个我不想与他人分享的代码仓库。 But I want to have a pod which others can integrate in their applications.但我想要一个 pod,其他人可以将其集成到他们的应用程序中。 Is that possible?那可能吗? I followed this tutorial but got the error on trying to add this on a different system: Unable to find specification for 'pod_name'.我按照本教程进行操作,但在尝试将其添加到其他系统时出现错误:无法找到“pod_name”的规范。
Here is the pod file:这是 pod 文件:
# Uncomment the next line to define a global platform for your project
#platform :ios, '9.0'
source 'https://github.com/my_source_url'
target 'DemoPods' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for DemoPods
pod 'MyPodName'
end
My use case:我的用例:
To distribute a closed source pod you first need to modify your private repository so that you can produce a .xcframework
file.要分发闭源 pod,您首先需要修改您的私有存储库,以便您可以生成一个.xcframework
文件。
You have to zip the .xcframework
file and make it available through a URL to your audience.您必须 zip .xcframework
文件并通过 URL 向您的观众提供。 (whether this is public or private) (无论这是公共的还是私人的)
Then you can create a .podspec
file like this:然后你可以像这样创建一个.podspec
文件:
Pod::Spec.new do |s|
s.name = '<POD_NAME>'
s.version = '<VERSION>'
s.summary = '<SUMMARY>'
s.description = <<-DESC
<DESCRIPTION>
DESC
s.homepage = '<A_URL_TO_A_WEBPAGE>'
s.author = { '<AUTHOR_NAME>' => '<AUTHOR_EMAIL>' }
s.source = { :http => '<URL_TO_YOUR_ZIP_FILE>' }
...
s.vendored_frameworks = '<PATH_OF_XCFRAMEWORK_FILE_IN_THE_ZIP>.xcframework'
end
After that there are 2 methods to distribute it:之后有两种分发方法:
Public : If you want to distribute your pod through cocoapods specs repo, you can push your .podspec
file to the cocoapods trunk following this guide:公共:如果您想通过 cocoapods 规范 repo 分发您的 pod,您可以按照本指南将您的.podspec
文件推送到 cocoapods 主干:
pod trunk push <PATH_TO_YOUR_PODSPEC_FILE>.podspec
The installation from the users will be like any other pod:用户的安装将与任何其他 pod 一样:
use_frameworks! target 'TargetName' do pod '<POD_NAME>' end
Private : For private distribution follow this quide, create a private specs repo and use the following command to push your podspec: Private :对于私有分发,请遵循此quide,创建一个私有 specs repo 并使用以下命令推送您的 podspec:
pod repo push <REPO_NAME> <PATH_TO_YOUR_PODSPEC_FILE>.podspec
The installation from the users will be like this:用户的安装将如下所示:
use_frameworks, target 'TargetName' do pod '<POD_NAME>': :source => '<PRIVATE_SPECS_REPO_URL>' end
Public : If you don't mind about cocoapods specs repo ( or if you want to test your .podspec
file ) you can make your .podspec
file publicly available through a URL and then instruct the users to use the podspec way in their Podfile
to install your pod:公开:如果您不介意 cocoapods 规格存储库(或者如果您想测试您的.podspec
文件),您可以通过 URL 公开您的.podspec
文件,然后指示用户在他们的Podfile
中使用podspec方式安装你的吊舱:
use_frameworks, target 'TargetName' do pod '<POD_NAME>': podspec. '<URL_TO_YOUR_PODSPEC_FILE>.podspec' end
Private : The same method also applies to the private distribution, as long as your users are the only ones that known or have access to the podspec URL. Private :同样的方法也适用于私有分发,只要您的用户是唯一知道或有权访问 podspec URL 的用户。
Although I don't recommend committing a binary file (which is the .xcframework
) into a git repo, you can pretty much do the same using a git repo but without the need to zip your .xcframework
file.尽管我不建议将二进制文件(即.xcframework
)提交到 git 存储库中,但您几乎可以使用 git 存储库执行相同的操作,但无需.xcframework
Create a git repository and add the .xcframework
file along with a .podspec
file like this:创建 git 存储库并添加.xcframework
文件和.podspec
文件,如下所示:
Pod::Spec.new do |s|
s.name = '<POD_NAME>'
s.version = '<VERSION>'
s.summary = '<SUMMARY>'
s.description = <<-DESC
<DESCRIPTION>
DESC
s.homepage = '<A_URL_TO_A_WEBPAGE>'
s.author = { '<AUTHOR_NAME>' => '<AUTHOR_EMAIL>' }
s.source = { :git => '<URL_TO_YOUR_GIT_REPO>.git', :tag => s.version.to_s }
...
s.vendored_frameworks = '<PATH_OF_XCFRAMEWORK_FILE_IN_THE_REPO>.xcframework'
end
Public : Then you can distribute your pod through cocoapods specs repo by pushing your .podspec
file to the cocoapods trunk like this:公共:然后您可以通过 cocoapods 规范 repo 分发您的 pod,方法是将您的.podspec
文件推送到 cocoapods 主干,如下所示:
pod trunk push <PATH_TO_YOUR_PODSPEC_FILE>.podspec
Private : For private distribution, you can create a private specs repo and use the following command to push your podspec: Private :对于私有分发,您可以创建一个私有规范 repo 并使用以下命令推送您的 podspec:
pod repo push <REPO_NAME> <PATH_TO_YOUR_PODSPEC_FILE>.podspec
If I understand your intentions correctly, you want to make your library public without opening the source code.如果我正确理解您的意图,您希望在不打开源代码的情况下公开您的库。 In this case, you should check out the example of GoogleWebRTC.在这种情况下,您应该查看 GoogleWebRTC 的示例。 This is their pods config .这是他们的pod 配置。
In this case, your cocoapod library would simply be a container for the built framework.在这种情况下,您的 cocoapod 库将只是构建框架的容器。 For example, you can create a public repository, which will store the information needed for cocoapods and the built framework itself.例如,您可以创建一个公共存储库,它将存储 cocoapods 和构建框架本身所需的信息。 I think It's even possible to configure github to publish builds from your private repo to the public one, but it may be a little bit challenging.我认为甚至可以配置 github 将构建从您的私人仓库发布到公共仓库,但这可能有点挑战。
You can check out this guide你可以看看这个指南
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.