美文网首页Mac&iOS常规使用
iOS podspec文件添加,支持pod

iOS podspec文件添加,支持pod

作者: 喝酸奶舔下盖 | 来源:发表于2018-08-22 15:09 被阅读1670次

瞎扯🥚

小菜鸡一直打算上传下自己写的一些小demo,上传过程中遇到了一些小问题再加上自己懒这个打算就搁浅了 ̄□ ̄||😂。刚好最近有时间,为了能睡的更香就把之前的坑填下。把关于文件上传github,添加podspec的过程记录下。如果有不对的地方欢迎大家指正,一起学习一块进步。

1.github创建私有仓库


创建仓库

2.把本地文件添加到github的仓库里(已经上传的跳到下一步)

cd 进入要上传的文件夹

git init //成功之后你会发现项目里多了一个隐藏文件夹.git

git add . //把所有文件添加到仓库

git commit -m “提交内容注释”

git remote add origin git@github.com:wangxuewen/WXWCategory.git //关联github仓库地址

git push -u origin master //上传本地代码

注意:要是第一次上传项目的话push之前要先git pull 一下。

通常git pull 默认在master分支,

执行命令:git pull origin master 

如果报错:

fatal: refusing to merge unrelated histories (原因是远程的仓库和本地的不一样)

执行git pull origin master --allow-unrelated-histories

3.创建项目的podspec文件

pod spec create WXWCategory 

这时候本地就生成一个iOS_Category.podspec文件

使用编辑器打开新生成的podspec文件,

Pod::Spec.new do |s|

s.name = "WXWCategory" #和文件名保持一致

s.version = "0.1.0" #新版本一般都是0.1.0(我也不知道为啥,猜的)

s.summary = "基础数据类型的分类"

s.description = "基础数据类型分类,方便使用" #description 要比summary长一些,不然会有警告,这个无所谓的,不想写就不写了

s.homepage = "https://github.com/wangxuewen/WXWCategory.git

s.license = { :type => "MIT", :file => "LICENSE" }

s.author = { "591807572@qq.com" => "591807572@qq.com" }

s.platform = :ios, "9.0"

s.source = { :git => "https://github.com/wangxuewen/WXWCategory.git", :tag => "0#{s.version}" }

s.source_files = "WWXCategory", "WWXCategory/**/*.{h,m}"

s.exclude_files = "Classes/Exclude"

4.验证podspec文件

 pod lib lint --allow-warnings # --allow-warnings 屏蔽警告

如果出现Error但是提示信息不足,可以添加--verbose 以获取更多错误信息

 pod lib lint --verbose

5.打tag 上传podspec

git tag -m"first tag WXWCategory" "0.1.0"

git push --tags

6.把podspec文件推送到CocoaPod官方库

 pod trunk push WXWCategory.podspec

7.用pod 搜索

pod search WXWCategory

新上传的库可能会搜不到,先pod setup更新我们本地的CocoaPods space库,如果还是不可以,清理下搜索缓存

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

再搜索就可以了。 (http://blog.sina.com.cn/s/blog_14d7dd6710102wc1w.html

出现的问题

error1:

- WARN | description: The description is shorter than the summary. - WARN | license: Unable to find a license file - ERROR | xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information. - NOTE | [OSX] xcodebuild: CocoapodTest/CocoapodTest/AppDelegate.h:9:9: fatal error: 'UIKit/UIKit.h' file not found - NOTE | [OSX] xcodebuild: CocoapodTest/CocoapodTest/APWheelSurfViewController.h:9:9: fatal error: 'UIKit/UIKit.h' file not found - NOTE | [iOS] xcodebuild: CocoapodTest/CocoapodTest/APWheelSurfViewController.m:12:9: fatal error: 'YYModel/YYModel.h' file not found - ERROR | [tvOS] unknown: Encountered an unknown error (Malformed version number string ) during validation.

解决方案:私有库的三方依赖用这种方式

  s.dependency "MJRefresh", "~> 3.1.12"

error2:

Specs satisfying the `YYModel (~> 1.0.4)` dependency were found, but they required a higher minimum deployment target.) during validation.

解决方案:Podfile 文件 中 platform:ios, ‘9.0’ 后边的 9.0 是平台版本号 ,一定要加上

error3:

-> WXWCategory (0.1.0) - ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.[!] The spec did not pass validation, due to 1 error.[!] Unable to read the license file `FILE_LICENSE` for the spec `WXWCategory (0.1.0)`[!] Unable to read the license file `FILE_LICENSE` for the spec `WXWCategory (0.1.0)`

这个错误也是使用指令pod trunk push WXWCategory.podspec 检查文件是否合法时发生的;

这个是在指定共享的类库时, 文件路径不对, 也就是设置s.source_files 字段时, 发生了错误, 这里的路径是相对于WXWCategory.podspec文件的, 如果是与WXWCategory.podspec同级的文件夹, 直接写文件夹名称即可, 如:

s.source_files = "WXWCategory"

如果有多级目录, 一定要逐级添加. 这里也可以这么写:

s.source_files = "WXWCategory/*.{h,m}" //或者s.source_files = "WXWCategory/*"

error4:

Unable to interpret the specified path `WXWCategory.podspec` as a podspec (Pod::DSLError).

podspec文件中有中文标点,仔细检查下😊

error5:

[!] Unable to read the license file `FILE_LICENSE` for the spec `WXWLuckView (0.0.1)`

本来默认生成的是: s.license = { :type => "MIT", :file => "FILE_LICENSE" }, 看错误的意思是找不到FILE_LICENSE这个文件,改成s.license = { :type => "MIT", :file => "LICENSE" }就好了,这个错误要多试下,看其他文章有不通的解决方法,可能是和环境有关系。

error6:

[!] Unable to accept duplicate entry for: WXWLuckView (0.0.1)

字面意思是不能接受重复输入,修改podspec文件中s.version与tag保持一致即可。

error7:

[!] {"name"=>["is already taken"]}

已经有重名的私有库

error8:

Authentication token is invalid or unverified. Either verify it with the email that was sent or register a new session.

邮箱重新验证下即可:

1.pod trunk register 你的邮箱

2.打开邮箱验证重新执行

3.pod trunk push podspec (提交podspec文件)

上传的demo(WXWCategory)

相关文章

网友评论

    本文标题:iOS podspec文件添加,支持pod

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