carthage 组件和
Last week I have a problem while making a pod for my SDK team. I ever made my own pod long time ago and it was very easy in the process. But this one was a different story. I need to make support of Cocoapod and Carthage and SPM for the project that is built within private repo but we want to distribute it globally. So what is the option? Pod and Carthage and SPM offer capabilities to share the project repo to being used widely by many people and they can easily integrate or even contribute to it. However how about a private repo project like an SDK? There is one solution we can use, distribute only the compiled binary source of the framework. So let’s start to make it! Follow these steps below:
上周,在为我的SDK团队制作广告连播时遇到了问题。 我很久以前曾经做过自己的广告连播 ,过程非常简单。 但这是一个不同的故事。 对于私人回购中构建的项目,我需要为Cocoapod和Carthage和SPM提供支持,但我们希望将其分发到全球。 那有什么选择呢? Pod and Carthage和SPM提供了共享项目回购协议的功能,可以被许多人广泛使用,他们可以轻松地集成甚至为它做出贡献。 但是,像SDK这样的私有仓库项目又如何呢? 我们可以使用一种解决方案,仅分发框架的编译二进制源。 因此,让我们开始吧! 请按照以下步骤操作:
- Make one public repository on Github only for the binary framework we want to distribute 在Github上仅为我们要分发的二进制框架建立一个公共存储库
- Put the binary framework there 将二进制框架放在那里
Yup, that's it ~ well wait !~. We still need to do some process to make it being acknowledged by both Carthage and Pod.
是的〜等等!〜。 我们仍然需要做一些过程,以使迦太基和Pod都认可它。
可可粉 (COCOAPOD)
For Cocoapod there are some steps that need to be done first make a new YourProductName.podspec file and write it like this
对于Cocoapod,首先需要完成一些步骤,以制作一个新的YourProductName.podspec文件,并像这样写
Pod::Spec.new do |s|
s.name = "YourProductName"
s.version = "3.2.6" // Change with your version
s.summary = "Brief summary." s.description = <<-DESC Your description. DESC
s.homepage = "Your website"
s.license = { :type => 'Copyright', :text => <<-LICENSE Copyright 2020 LICENSE }
s.author = { "$(git config user.name)" => "$(git config user.email)" }
s.source = { :git => "https://github.com/YourRepo.git", :tag => "#{s.version}" }
s.vendored_frameworks = 'YourProduct.framework', 'YourProductA.framework'
s.platform = :ios
s.swift_version = "5" s.ios.deployment_target = '9.0'
end
As you can see above you need to add this one and update it every time make a new release. For s.vendored_frameworks you can fill in as many dependencies as you have separated by commas. Later on, they just do a one-time pod command and can automatically figure out the dependencies needed.Once this one did then do this
如您在上面看到的,您需要添加此版本并在每次发布新版本时对其进行更新。 对于s.vendored_frameworks,您可以填写以逗号分隔的尽可能多的依赖项。 稍后,他们只需执行一次pod命令,即可自动找出所需的依赖项。
pod repo add YourProductName https://github.com/YourRepo.git
Wait for the process above until finished, then you can add the tag of your branch to the remote branch after you add the tag then do this
等待上面的过程直到完成,然后您可以在添加标签后将分支的标签添加到远程分支,然后执行此操作
pod repo push YourProductName YourProductName.podspec
Once this process is done, then your pod is ready to use!. Now navigate to other project and add this to your Podfile (you can omit the version to always fallback to latest supported version)
完成此过程后,即可使用您的吊舱! 现在导航到其他项目并将其添加到您的Podfile中(您可以忽略该版本以始终回退到最新的受支持版本)
pod 'YourProductName', '0.0.1', :source => "https://github.com/YourRepo.git"
If you have a newer version on your tag, always do this command below every time to update the pod repo. (And update your podspec as well)
如果您的标签上有较新的版本,请始终在下面每次执行以下命令来更新Pod存储库。 (并更新您的podspec)
pod repo push YourProductName YourProductName.podspec
迦太基 (CARTHAGE)
For Carthage, it is a very easy setup. Compress all of the binary that you want to share and rename it as per the name you want to use for it. Now go to the repo and place it there, however, let put our .gitignore
so git won’t push it to the remote repo like below:
对于迦太基来说,这是一个非常简单的设置。 压缩要共享的所有二进制文件,并根据要使用的名称将其重命名。 现在转到存储库并将其放置在此处,但是,让我们放入.gitignore
这样git不会像下面那样将其推送到远程存储库:
.DS_Store
*.zip
Then add new JSON (YourProductName.json) that contained the version and the link of the binary like below:
然后添加新的JSON(YourProductName.json),其中包含版本和二进制文件的链接,如下所示:
{
"0.0.1": "https://github.com/YourRepo/releases/download/0.0.1/YourProductName.zip"
}
If you see the pattern above then we do still need one more step, we must make a release on our git repo. Go to the Releases
and click Draft new releases. Remember you need to add the tag beforehand so they are able to search the related tag.
如果您看到上面的模式,那么我们仍然需要再做一步,我们必须在git repo上发布一个版本。 转到Releases
,然后单击草拟新发行版。 请记住,您需要预先添加标签,以便他们能够搜索相关标签。
Once you go to this page, fill in all necessary information then attach the .zip and .json on the Attach binaries ....
row. After that publish the release.
转到此页面后,填写所有必要的信息,然后将.zip和.json Attach binaries ....
到“ Attach binaries ....
行。 之后,发布版本。
Once it is done now you can do this on your other project Cartfile below:
一旦完成,您可以在下面的其他项目Cartfile上执行此操作:
binary "https://github.com/YourRepo/releases/download/0.0.1/YourProductName.json" ~> 0.0.1
Make sure the 0.0.1 is the destination of the release version we want to use.
确保0.0.1是我们要使用的发行版本的目标。
Finally, everything is done! Now you are able to make your binary framework public and being used by the client without exposing your private code to them! The only thing left now only SPM, once I figure it out how to make it then I will make another article for that. However there is a disadvantage for this way, we need to manually put the release every time in this public repo and carefully managing the podspec and the .zip as well .json.
最后,一切都完成了! 现在,您可以将二进制框架公开并被客户端使用,而无需将私有代码暴露给他们! 现在唯一剩下的只有SPM,一旦我弄清楚如何制作它,我将为此写另一篇文章。 但是这种方式有一个缺点,我们需要每次手动将发布版本放入此公共仓库中,并仔细管理podspec和.zip以及.json。
carthage 组件和