利用cocoapods管理开源项目,支持 pod install安装整个流程记录(github公有库)

利用cocoapods管理开源项目,支持 pod install安装整个流程记录(github公有库),完成预期的任务,大体有下面几步:javascript

1.代码提交到github平台html

2.建立.podspecjava

3.编辑.podspecios

4.添加taggit

5.验证github

6.注册CocoaPodsjson

7.发布swift

详细流程以下:

1.代码提交到github平台

将本身的代码上传到github上面(不是惟一的,上传到任何平台上均可以,前提是项目是开源的)。至于怎么利用github管理咱们的项目,能够参考:http://www.cnblogs.com/richard-youth/p/4684100.html

2.建立.podspec

首先要利用cocoapods将项目管理起来,具体能够参考:http://www.cnblogs.com/richard-youth/p/4508049.html
而后cd到你项目的目录,执行命令( yooweiTest这个是你框架的名称)
$ pod spec create yooweiTest

3.编辑.podspec

建立好后打开,删除注释, 前面有#的为注释,若是你想知道每一个东西的含义能够了解一下

整理以后的文件
yooweiTestyooweiTesthttps://github.com/yoowei/yooweiTest     s.license= { :type => "MIT", :file => "LICENSE" }
https://github.com/yoowei/yooweiTest.git.git结尾。
s.source_files  = "yooweitest", "yooweitest/**/*" //须要和.podspec 的名称同样??Pod::Spec.new do |s| s.name = ""
s.version = "1.0"
s.ios.deployment_target = '7.0'
s.summary = ""
s.homepage = "
"
s.author = { "yoowei" => "yoowei@126.com" }
s.source = { :git => "
", :tag => s.version } /注意须要
接下来说解一下每行代码的含义
s.name:名称,pod search 搜索的关键词,注意这里必定要和.podspec的名称同样,不然报错
s.version:版本号
s.ios.deployment_target:支持的pod最低版本
s.summary: 简介
s.homepage:项目主页地址
s.license:许可证
s.author:做者
s.social_media_url:社交网址
s.source:项目的地址
s.source_files:须要包含的源文件
s.resources: 资源文件
s.requires_arc: 是否支持ARC
s.dependency:依赖库,不能依赖未发布的库
s.dependency:依赖库,若有多个能够这样写
s.license= { :type => "MIT", :file => "LICENSE" }
这里建议你们这样写,若是写别的会报警告,致使后面一直提交失败
  • source_files:写法及含义建议你们写第一种或者第二种
    "yooweitest/* "yooweitest/yoowei/*.{h,m}" "yooweitest/**/*.h"
  • “*” 表示匹配全部文件
  • “*.{h,m}” 表示匹配全部以.h和.m结尾的文件
  • “**” 表示匹配全部子目录
  • s.source 常见写法
    s.source = { :git => "https://github.com/yoowei/yooweiTest.git", :commit => "68defea" } s.source = { :git => "https://github.com/yoowei/yooweiTest.git", :tag => 1.0.0 } s.source = { :git => "https://github.com/yoowei/yooweiTest.git", :tag => s.version }
  • commit => "68defea" 表示将这个Pod版本与Git仓库中某个commit绑定
  • tag => 1.0.0 表示将这个Pod版本与Git仓库中某个版本的comit绑定
  • tag => s.version 表示将这个Pod版本与Git仓库中相同版本的comit绑定
另外:
一、引用静态库: “(.ios).library”。去掉头尾的lib,用“,”分割 。注意: (.ios)括号括起来表明能够省略
// 引用libxml2.lib和libz.lib.   
spec.libraries = 'xml2', 'z'
二、引用公有framework:"(.ios).framework" 用”,”分割. 去掉尾部的”.framework”
spec.frameworks = 'UIKit','SystemConfiguration', 'Accelerate'
三、引用本身生成的framework:’(.ios).vendored_frameworks’  用”,”分割 路径写从.podspec所在目录为根目录的相对路径 ps:这个不要省略.framework spec.ios.vendored_frameworks = 'Pod/Assets/*.framework'
四、引用本身生成的.a文件, 添加到Pod/Assets文件夹里. Demo的Example文件夹里也须要添加一下, 否则找不到
spec.ios.vendored_libraries = 'Pod/Assets/*.a'
注意:在提交到私有仓库的时候须要加上--use-libraries 

4.建立LICENSE(许可证/受权)文件,此文件必需要有

建立一个文件名字命名为LICENSE,内容为:只须要把前面的版权改一下就好了,后面的都同样。

MIT LicenseCopyright (c) 2017Permission is hereby granted, free of charge, to any person obtaining a copyvim

of this software and associated documentation files (the "Software"), to dealxcode

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

SOFTWARE.

可是:通常咱们建立仓库的时候,大多数已经建立好了的。

5.上传到Git

将包含配置好的 .podspec, LICENSE 的项目提交 Git仓库

6.打tag

$ git tag
1.0
$ git tag -a 2.0 -m "2.0版本"
$ git tag
1.0
2.0
$ git push origin 2.0
Counting objects:
1, done.Writing objects: 100% (1/1), 173 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)To https://github.com/yoowei/yooweiTest.git 
* [new tag]         2.0 -> 2.0
由于cocoapods是依赖tag版本的,因此必须打tag。之后再次更新只须要把你的项目打一个tag,而后修改.podspec文件中的版本,接着提交到cocoapods官方就能够了。
注意将tag提交这一步很重要

7.验证.podspec文件

到此检查一下你工程下面的文件, 你的项目, .podspec文件, LICENSE文件是否存在。验证会先测试本地 .podspec 文件是否存在语法错误.
// --verbose 若是验证失败会报错误信息
$ pod spec lint yooweiTest.podspec --verbose
说明:2017.1.14 我将mac电脑系统升级到最新,所须要的cocoapods等环境从新更新安装,包括该项目再github上面的项目仓库也是从新创建的(通过修改),此次验证竟然一次性经过,没有出现任何问题。
 yooweiTest.podspec passed validation.

前段时间操做遇到的错误和警告:

一、

-> yooweiTest (1.0)
    - WARN  | github_sources: Github repositories should end in `.git`. //注意须要以.git结尾
    - WARN  | description: The description is equal to the summary.
    - NOTE  | xcodebuild:  warning: no rule to process file 'yooweiTest/JSPatchtest/yoowei/JSPatch.js' of type sourcecode.javascript for architecture i386
    - NOTE  | xcodebuild:  warning: no rule to process file 'yooweiTest/JSPatchtest/yoowei/JSPatch.js' of type sourcecode.javascript for architecture x86_64

Analyzed 1 podspec.
[!] The spec did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
    `echo "2.3" > .swift-version`.
$ pod lib lint --allow-warnings

$ echo "2.3" > .swift-version

二、 -> JSPatchtest (1.0.0)

    - ERROR | name: The name of the spec should match the name of the file.// 这个是要保证.podspe文件的名称和里面s.name保持一致

    - WARN  | github_sources: Github repositories should end in `.git`.

    - WARN  | description: The description is equal to the summary.

    - ERROR | [iOS] unknown: Encountered an unknown error (No podspec found for `JSPatchtest` in `/Users/galahad/Desktop/yooweiTest`) during validation.

[!] JSPatchtest did not pass validation, due to 2 errors and 2 warnings.

3  、

[!] Error installing JSPatchtest
 -> yooweitest (1.0.0)
    - WARN  | description: The description is shorter than the summary.
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/yoowei/yooweiTest.git /var/folders/rg/gmjp61bx0x95t4tjx2hh_3sr0000gn/T/d20170113-4028-cvivmq --template= --single-branch --depth 1 --branch 1.0.0

[!] The spec did not pass validation, due to 1 error and 1 warning.

解决方法:执行 sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer (-switch 后面加上你的Xcode.app包内容里的Developer的文件夹路径便可).

验证成功后:

yooweiTest passed validation.

验证失败:

[!] The spec did not pass validation, due to 1 error.

若是出现错误,就各式各样,根据描述进行解决就能够了。

8.注册Trunk

若是要添加到Cocoapods的官方库了,可使用trunk工具,具体能够查看官方文档。若是是私有库的话,详见:http://www.cnblogs.com/richard-youth/p/6289015.html
trunk须要CocoaPods 0.33版本以上,用pod --version 命令查看版本,若是CocoaPods版本低,须要升级。已经注册过的不须要注册,怎么看本身有没有注册
$ pod trunk me
- Name:     yoowei 
- Email:    yoowei@126.com 
- Since:    January 12th, 04:38 
- Pods:     None 
- Sessions:    - January 12th, 04:38 - May 21st, 03:35. IP: 218.205.57.27
若是没有注册的话  [!] You need to register a session first.注册
// 加上--verbose能够输出详细debug信息,方便出错时查看。
$ pod trunk register yoowei@126.com "yoowei" --verbose
[!] Please verify the session by clicking the link in the verification email that has been sent to yoowei@126.com
注册完成以后会给你的邮箱发个邮件,进入邮箱邮件里面有个连接,须要点击确认一下。

补充: 
$ pod trunk help 能够查询通常的命令
那么怎么将本身删除????
其实咱们能够连根拔起,
# 显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles Yes && killall Finder
# 不显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles No && killall Finder

咱们显示隐藏文件后,在用户目录下,找到 /Users/galahad/.rvm 

直接将隐藏文件.rvm删除
$ pod trunk me
-bash: /Users/galahad/.rvm/gems/ruby-2.2.2/bin/pod: No such file or directory
一切OK🌶

9.发布

发布时会验证 Pod 的有效性,若是你在上面步骤中手动验证 Pod 时使用了 --use-libraries 或 --allow-warnings 等修饰符,那么发布的时候也应该使用相同的字段修饰,不然出现相同的报错。
--allow-warningspod trunk push yooweiTest.podspec 
成功了之后会出现如下内容

这个时候,再用
$ pod trunk me 
- Name:     yoowei 
- Email:     yoowei@126.com 
- Since:     January 12th, 04:38 
- Pods:    - yooweiTest 
- Sessions:    - January 12th, 04:38 - May 22nd, 00:54. IP: 218.205.37.37
你会发现- Pods:    - yooweiTest 已经有了内容了。
 
10.验证
当即搜索
$ pod search yooweiTest
[!] Unable to find a pod with name, author, summary, or description matching `yooweiTest`
没有搜到......
本身摸索着......进行如下尝试
首先:
$ pod setup
而后:
 

$ pod search yoowei

[!] Unable to find a pod with name, author, summary, or description matching `yoowei`

仍是失败......
因为 pod setup成功后会生成~/Library/Caches/CocoaPods/search_index.json文件。

终端输入rm ~/Library/Caches/CocoaPods/search_index.json

删除成功后再执行pod search 一切OK🌶

$ rm ~/Library/Caches/CocoaPods/search_index.json

$ pod search yoowei

Creating search index for spec repo 'master'.. Done!

$ pod search yoowei

-> yooweiTest (1.0)

   yooweiTest just test.

   pod 'yooweiTest', '~> 1.0'

   - Homepage: https://github.com/yoowei/yooweiTest

   - Source:   https://github.com/yoowei/yooweiTest.git

   - Versions: 1.0 [master repo]

 
补充:Claim your Pod 声称,索取: https://trunk.cocoapods.org/claims/new 
能够利用 pod trunk info yooweiTest 查询相关信息
$ pod trunk info yooweiTest
yooweiTest   
- Versions:      - 1.0 (2017-01-14 06:50:53 UTC)   
- Owners:      - yoowei <yoowei@126.com> 
点击SEND进入页面后: $ pod trunk help 能够查询通常的命令,包括添加开发者
我的理解:最后无论你是否是有争议,他们要求你说明为何来到这里,我以为你想写就写,不写拉倒。 若有不对,欢迎交流。
相关文章
相关标签/搜索