美文网首页
创建自己的第一个 cocoaPod

创建自己的第一个 cocoaPod

作者: _zhang__ | 来源:发表于2021-08-26 10:49 被阅读0次

创建 Git 仓库

创建 Git 仓库,包含 MIT License
项目 clone 到本地,将 打包的 framework 拖入

工程文件夹

创建 pod

1、创建 podspec 文件

终端,cd 到仓库目录下,创建 podspec文件

pod spec create testSDK // testSDK 是 pod 库名

testSDK.podspec文件如下

image.png
#
#  Be sure to run `pod spec lint frameWorkName.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |spec|
  # .spec 文件名
  spec.name         = "SDKName"
  # SDK 版本号
  spec.version      = "1.0.0"
  spec.summary      = "SDK 的简洁概述"
  spec.description  = "SDK 的介绍"

  # 仓库地址
  spec.homepage     = "https://gitee.com/bbavip/sdk-name”
  
  #spec.license      = "MIT"
  spec.license      = { :type => "MIT", :file => "LICENSE" }
  # 用户信息
  spec.author             = { “name” => “email@qq.com" }
  
  spec.platform    = :ios 
  spec.requires_arc = true
  # 开源地址和版本号(同 tag 版本一致)
  spec.source       = { :git => "https://gitee.com/bbavip/sdk-name.git", :tag => "#{spec.version}" }

  # 资源文件
  spec.resource     = 'Classes/frameWorkName.framework/PicResource.bundle'

  # 开源出去的文件/文件夹
  #spec.source_files  = "Classes", "Classes/**/*.{h}" 
  spec.source_files  = 'Classes/frameWorkName.framework/Headers/*.{h}'

  # 公开的头文件
  #spec.public_header_files = "Classes/**/*.h"
  spec.public_header_files = 'Classes/frameWorkName.framework/Headers/frameWorkHeader.h’ 
  
  #spec.exclude_files = "Classes/Exclude"
  #spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }

  # 依赖的系统框架
  spec.frameworks = 'AVKit','CoreGraphics','SystemConfiguration','AudioToolbox','QuartzCore','CoreLocation','AVFoundation','Foundation','UIKit'
  # 依赖的系统静态库
  spec.library = 'c++','z'

  # 自己的 .framework
  #spec.vendored_frameworks = "Classes/*.{framework}"
  spec.vendored_frameworks = 'Classes/frameWorkName.framework'

  # 自己的 .a
  #spec.ios.vendored_libraries = "Classes/frameWorkName.a"

  # 依赖的第三方 framework
  spec.subspec 'iflyMSC' do |ifly|
  ifly.source_files       = 'Classes/iflyMSC.framework/Headers/*.{h}'
  ifly.public_header_files = 'Classes/iflyMSC.framework/Headers/IFlyMSC.h' 
  ifly.vendored_frameworks = 'Classes/iflyMSC.framework' 
  end

  # 依赖的第三方 pod 库
  spec.dependency "AFNetworking"
   
end
  • 相关报错
    - ERROR | [iOS] file patterns: Thesource_filespattern did not match any file
    source_files路径问题,spec.source_files路径是基于.podspec文件的。

2、验证 podspec 文件

cd 到 testSDK.podspec文件所在文件夹

// 本地验证
pod lib lint
// 允许警告,解决因警告导致验证不过的问题;verbose:显示验证过程的详细过程信息
pod lib lint --allow-warnings --verbose 
  • 相关报错
  1. - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://xxx.git /var/folders/v_/v95fqz3x45n__zm562jddlhm0000gn/T/d20210819-53525-1tnf8eh --template= --single-branch --depth 1 --branch 1.0.5
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer (Xcode.app包的Developer的文件夹路径)
验证 spec - error2

原因:.podspec文件中 spec.platform = :iOS 导致的错误,应该是:spec.platform = :ios .

  1. ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code
pod lib lint --allow-warnings --verbose --skip-import-validation

验证成功:

podspec 验证通过

3、Git 打 tag

git tag "1.0.0" // tag版本
git push --tags // 将 tag 推送到远程仓库

cocoapod 是依赖于tag版本的,必须打tag,
tag版本与.podspec文件中的spec.version 版本要保持一致。

4、远程验证 podspec

// 本地和远程 验证
pod spec lint

5、发布到 cocoapod

cd 到.podspec文件所在

pod trunk push *.podspec --allow-warnings

trunk注册

pod trunk register 你的邮箱@email.com --description= '名字'

按照提示,收到邮箱后验证。
验证后,再次执行

pod trunk push *.podspec --allow-warnings
  • 相关报错
  1. [!] Unable to accept duplicate entry for: XXXXX (1.0.0)
    已存在版本号,不允许相同版本的提交,更换.podspec文件中的spec.version即可。
  2. - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code
pod trunk push *.podspec --allow-warnings --skip-import-validation
cocoapod 库成功

查看,终端执行:

pod trunk me 
image.png

6、搜索

pod search xxx // xxx: 刚刚push成功的库
  • 相关报错
    [!] Unable to find a pod with name, author, summary, or description matching xxx
    清掉缓存后,再次搜索
rm ~/Library/Caches/CocoaPods/search_index.json
  • cocoapods 可能存在延迟,可稍待一段时间(时长不定)再进行搜索

7、删除 pod 官方库中某个意外版本

// SDKName:库名  1.0.0:要删除的版本
pod trunk delete SDKName 1.0.0
image.png

根据终端提示输入 y,回车,即删除此版本。

相关文章

网友评论

      本文标题:创建自己的第一个 cocoaPod

      本文链接:https://www.haomeiwen.com/subject/mobgbltx.html