瞎扯🥚
小菜鸡一直打算上传下自己写的一些小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文件)
error9:
[!] Error installing libwebp
[!] /usr/bin/git clone https://chromium.googlesource.com/webm/libwebp /var/folders/gr/3pwv50y90db54sygb37d32jh0000gn/T/d20190923-34418-1n7wqfk --template= --single-branch --depth 1 --branch v1.0.2
Cloning into '/var/folders/gr/3pwv50y90db54sygb37d32jh0000gn/T/d20190923-34418-1n7wqfk'...
fatal: unable to access 'https://chromium.googlesource.com/webm/libwebp/': Failed to connect to chromium.googlesource.com port 443: Operation timed out
更换libwebp源文件的下载链接
a. Finder -> 前往文件夹 (⇧⌘G) 👉 ~/.cocoapods/repos/master/Specs/1/9/2/libwebp
b.把https://chromium.googlesource.com/webm/libwebp 替换为 https://github.com/webmproject/libwebp.git 并保存
c.重新pod install
error10:
$ Specs satisfying the `QMUIKit (~> 4.1.3)` dependency were found, but they required a higher minimum deployment target
问题原因:找到了依赖项,但需要更高的最低部署目标,调整 podfile文件中platform :ios,'8.0' 更新到高版本或者把目标依赖"QMUIKit"的版本调低
error11:
GET https://gems.ruby-china.org/specs.4.8.gz
404 Not Found
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)
https://gems.ruby-china.org/ 访问不了
域名改为
具体操作如下图:
error12:
git@gitee.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
问题原因:本地没有生成ssh公钥或者生成的ssh有问题。
解决思路:
1.当你没有ssh公钥的时候,在Terminal中执行(其中gitee_id_rsa为你要生成的ssh公钥的文件名称,xxxx@qq.com为你的邮箱)
ssh-keygen -t rsa -C 'xxxx@qq.com' -f ~/.ssh/gitee_id_rsa
2. 执行ssh -v git@github.com,过程中输入yes
ssh -v git@github.com
3. 执行 ssh-agent -s
ssh-agent -s
4.执行 ssh-add ~/.ssh/gitee_id_rsa
ssh-add ~/.ssh/gitee_id_rsa
如果出现问题 "could not open a connection to your authentication agent",则执行 eval `ssh-agent -s` 之后再执行 ssh-add ~/.ssh/gitee_id_rsa
5.执行 ssh -T git@gitee.com,验证是否配置成功。出现下面结果则恭喜你啦