美文网首页
发布自己框架到CocoaPods

发布自己框架到CocoaPods

作者: 朱晓晓的技术博客 | 来源:发表于2018-01-23 16:06 被阅读231次

关于这个问题,操作问题上并不算复杂,难在于坑多以及处理问题
相关资料来源如下:
1.如何发布自己的开源框架到CocoaPods
2.Git命名使用
3.iOS之创建CocoaPods公有库采坑记
4.CocoaPods podspec lint failure - file not found
5.# Error 'xcodebuild: Returned an unsuccessful exit code' after trying publishing Pod

6.iOS开发-- 创建podspec文件,为自己的项目添加pod支持
7.3分钟让你的框架支持cocoapods,podspec文件讲解
8.把自己Github上的代码添加Cocoapods支持
9.iOS,制作属于自己cocoapods,(framework,bundle)
10.解决因 Cocoapods 版本原因导致的 pod trunk push 问题
11.Pod提示Remote branch not found in upstream origin
12.git删除远程分支和tag相关命令

制作cocoapods步骤:

1.在自己的GitHub上创建代码仓库,并拷贝地址
image.png
image.png
2.拉取仓库到本地
image.png
image.png
3.拷贝自己的要Pod的项目代码到文件目录,并且通过命令行cd到改目录下
image.png image.png
4.使用命令行添加自己的项目,然后提交到github上
git add .
git commit -m "我要提交项目"
git push origin master
命令行提交
刷新GitHub,看到代码成功上传
5.创建.podspec
pod spec create myTest20180120
image.png
image.png

注意创建后千万不要用文本工具编辑,容易导致出错,建议使用可编译工具,
6-1>可以用atom编辑
6-2>可以用vim命令编辑,vim状态下,按i进入编辑状态,按esc退出编辑状态,然后输入:wq保存退出编辑

6.编辑podSpec文件,用atom打开
image.png image.png

  s.name         = "myTest20180120"
  s.version      = "0.0.1"
  s.summary      = "summary描述,谢谢"
  s.description  = "这是第一次发布"
  s.homepage     = "https://github.com/OwenJoe/myTest20180120"
  s.license      = { :type => "MIT", :file => "LICENSE" }
  s.author             = { "zhwb" => "zhuwb@hori-gz.com" }
  s.source       = { :git => "https://github.com/OwenJoe/myTest20180120.git", :tag => "0.01" }
  s.source_files  = "MyDemo/**/*.{h,m}"
  s.requires_arc = true
  s.frameworks  = "UIKit"
  s.platform     = :ios, "7.0"
  s.xcconfig = { "FRAMEWORK_SEARCH_PATHS" => "$(PLATFORM_DIR)/Developer/Library/Frameworks" }
 
image.png
s.name:名称,pod search 搜索的关键词,一定要和.podspec的名称一样,否则报错

s.version:版本号

s.ios.deployment_target:支持的pod最低版本

s.summary: 简介

s.homepage:项目主页地址

s.license:开源协议(创建github库的时候选择的)

s.author:作者信息(这里随便谢谢也可以通过)

s.social_media_url:社交网址

s.source:项目的地址

s.source_files:需要包含的源文件

s.resource:资源文件,单个

s.resources: 资源文件(含bundle)

s.requires_arc: 是否支持ARC

s.dependency:依赖库,不能依赖未发布的库.如AFNetWorking

s.vendored_frameworks:包含的framework,也就是我们自己制作的pod

s.description:描述,字数要比s.summary长

s.screenshots:截图

s.exclude_files:隐藏的文件

s.public_header_files:公开的头文件

s.framework:所需的framework,单个

s.frameworks:所需的framework,多个用逗号隔开

6-1>s.vendored_libraries:包含的的.a

6-2>多个s.dependency可以这样写,(可以加上版本号):

s.dependency = 'AFNetworking', '~> 2.3'
s.dependency = 'SDWebImage'
s.dependency = 'AFNetworking'

6-3>s.license可以用下面2中写法:

s.license = "MIT" 会有一个警告
s.license = { :type => "MIT", :file => "LICENSE" }

6-4>s.source_files:写法及含义:
这个地方出错的几率是百分八十以上,后边会接着说

"MyDemo/*
"MyDemo/*.{h,m}"
"MyDemo/**/*.h"
“” 表示匹配所有文件
“.{h,m}” 表示匹配所有以.h和.m结尾的文件
“**” 表示匹配所有子目录

6-5>s.source 常见写法

/// git commit -m =>"13287dd",讲pod版本与git仓库中的某一次提交绑定
s.source = { :git => "https://github.com/lixianshen/CFMobAdSDK", :commit => "13287dd" }

/// 将这个Pod版本与Git仓库中某个版本的comit绑定 
s.source = { :git => "https://github.com/lixianshen/CFMobAdSDK", :tag => 1.0.0 }

/// 将这个Pod版本与Git仓库中相同版本的comit绑定
s.source = { :git => "https://github.com/lixianshen/CFMobAdSDK", :tag => s.version }
7.编辑完podspec文件后,需要验证一下这个文件是否可用,验证一下podspec这个文件是否可用,如果有任何WARNING或者ERROR都是不可以的,它就不能被添加到Spec Repo中,不过xcode的WARNING是可以存在的,验证需要执行命令:(二选一)
1.pod spec lint MyDemo.podspec
2.pod lib lint 

注意:
pod lib lint --allow-warnings :表示验证时候,忽略警告
pod lib lint --verbose :表示验证如果出错会显示更详细的错误信息
当出现"XXX passed validation" 表示成功,Warning可以忽略


image.png
8.需要为您的Pod标记一个与您的版本号相对应的标签,否则会报错
git tag 'v0.1.0' # the version number you're using for this release
git push --tags
image.png
9. 注册CocoaPods账号
pod trunk register 邮箱地址 ‘用户名’ —description='描述信息'

例如:
pod trunk register mayun@126.com ‘mayun’ —description='ioser'

image.png
黄色提示已经发送了一个验证码到邮箱,你可以打开你的邮箱验证即可。打开邮件中的链接后如下:
image.png
这样就成功注册了Cocoapods账号。
如果已经注册过,则可以直接忽略.
10.查看注册信息
pod trunk me
image.png
11.发布自己的.podspec到cocoapods
pod trunk push myTest20180120.podspec

如果有警告用:pod trunk push myTest20180120.podspec --allow-warnings
这样就表示成功了


image.png
12.检查自己发布的pod

检查之前先删除缓存中的json文本 ~/Library/Caches/CocoaPods/search_index.json

image.png
如果不删除,会搜索不到自己发布的,如果让你朋友也要查到也要删除现有的缓存
12.搜索记录
image.png

各种Error集合

1.出现各种提交内容为空,或者重复如下:


image.png

解决:打开podspec,按错误提示修改

2.pod lib lint 出现XCTest 文件未找到
解决:
2-1>打开你要上传的项目,在BulidSetting中输入,FRAMEWORK_SEARCH_PATHS
Framework Search Path中添加$(PLATFORM_DIR)/Developer/Library/Frameworks

image.png
2-2>在podspec中添加s.xcconfig = { "FRAMEWORK_SEARCH_PATHS" => "$(PLATFORM_DIR)/Developer/Library/Frameworks" }

3.最后所有的验证都通过了也上传成功了,结果使用pod search仍然搜索不到。


image.png

解决:
3-1、执行pod setup,如果最底下会输出setup completed。说明执行pod setup成功。


image.png

4.1>- ERROR | [iOS] file patterns: The source_files pattern did not match any file.
解决: 文件路径不对, 也就是设置 s.source_files 字段时, 发生了错误

4-2>- ERROR | [iOS] file patterns: The vendored_frameworks pattern did not match any file.
解决: framework路径不对, 也就是设置 s.vendored_frameworks 字段时, 发生了错误

5.出现fatal: Remote branch v0.0.1 not found in upstream origin
原因:这里因为从远端拉不到v0.0.1branch而引起的报错。

解决: image.png

相关文章

网友评论

      本文标题:发布自己框架到CocoaPods

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