文章目录
一、准备工作
1.申请账号 (已有账号的请忽略)
GitHub官网,申请流程很简单,不再赘述
2.创建GitHub仓库
License文件,建议选择 MIT
3.将本地项目上传到GitHub仓库
(1)打开终端,cd到想要放项目的根目录下
cd 文件目录
(2)将远程仓库克隆到本地
git clone 仓库的git链接
链接在这里
(3)将测试自己SDK的demo放到这个文件夹中,并添加到本地仓库
git add .
(4)将添加的文件commit到本地
git commit -m “版本说明”
(5)将本地仓库的代码推送到GitHub仓库
git push
(6)之后就能在GitHub仓库中看到自己上传的代码了
二、创建podspec文件
1.注册trunk账号
(1)注册前,先检查一下当前的Cocoapods的版本是否在0.33及以上
pod --version
如果版本太低,需要升级,执行以下命令
sudo gem install cocoapods
(2)注册账号
pod trunk register 邮箱 ‘名字’ --description=‘imac’ --verbose
邮箱和名字中间和前后都有空格,名字需要加单引号
–description是简介,加不加都可以,加上 --verbose 可以看到详细信息。如果顺利的话你会收到一份邮件,需要点击验证。
(3)查看自己注册的信息
pod trunk me
注册成功是这样的,会显示名字邮箱时间等注册信息
2.配置podspec文件
(1)创建podspec文件
cd 到工程目录下
在终端中输入
pod spec create 名字
或者
pod spec create GitHub仓库链接
比如我创建的名字是QCXMyLogin
仓库链接是https://github.com/qcx123/QCXMyLogin
之后就会在这个目录下生成QCXMyLogin.podspec文件,将它拖到Xcode图标上,即打开
(2)podspec文件详解
Pod::Spec.new do |spec|
spec.name = "QCXMyLogin"
spec.version = "0.0.2"
spec.summary = "我的登录SDK"
spec.homepage = "https://github.com/qcx123/QCXMyLogin"
spec.license = "MIT"
spec.author = { "qcx123" => "email@address.com" }
spec.platform = :ios, "9.0"
spec.source = { :git => "https://github.com/qcx123/QCXMyLogin.git", :tag => spec.version }
spec.source_files = "QCXMyLogin", "MyLoginDemo/MyLoginDemo/MyLogin/*.{h,m}"
spec.frameworks = "UIKit"
spec.vendored_frameworks = "MyLoginDemo/MyLoginDemo/MyLogin/MyLogin/MyLoginSDK.framework","MyLoginDemo/MyLoginDemo/MyLogin/SDK/ALoginSDK.framework","MyLoginDemo/MyLoginDemo/MyLogin/SDK/BLoginSDK.framework"
spec.resource = "MyLoginDemo/MyLoginDemo/MyLogin/MyLogin.bundle"
spec.requires_arc = true
spec.pod_target_xcconfig = { 'VALID_ARCHS' => 'x86_64 armv7 arm64' }
end
spec.name
必须和这个文件的名字相同
spec.version
当前的版本号,要与稍后的GitHub上的tag同步
spec.summary
简单描述
spec.description
= <<-DESC
详细描述
DESC
spec.homepage
GitHub仓库地址
spec.license
和创建时候填一样的 MIT
spec.author
名字和邮箱
spec.platform
系统和最低支持的版本
spec.source
git的地址和tag号 tag => specversion 即可
spec.source_files
这个是以后通过pod下载下来的代码文件,注意路径,第一个双引号内是本地仓库的名字,第二个双引号是具体的.h和.m的路径,从工程名字开始,如果要包含MyLogin和他的子文件夹中的所有.h和.m,第二个双引号可以这么写"MyLoginDemo/MyLoginDemo/MyLogin/**/*.{h,m}"
spec.frameworks
用到的系统框架,这里可以写多个,用逗号分隔
spec.libraries
依赖的系统资源
spec.vendored_frameworks
用到的你手动拖入工程的三方SDK,这些到时候在使用时也会跟着一起下载下来,同样注意路径,这里可以写多个,用逗号分隔
spec.resource
用到的资源文件,如果有多个可以这么写"MyLoginDemo/MyLoginDemo/MyLogin/**/*.{bundle, plist,json}
spec.vendored_libraries
用到的你手动拖入工程的三方.a,同样是注意路径
spec.dependency
依赖的第三方库,通过pod导入的,如spec.dependency “SDWebImage”, “~> 3.8”,可以写多个,后边最好跟版本号,避免不必要的错误
spec.requires_arc
支持ARC
spec.pod_target_xcconfig
这个是稍后验证的时候,当报这个错的时候添加的:
The following build commands failed: Ld /Users/xxx/Library/Developer/Xcode/DerivedData/App-dowuptsdrqujrrfdnfxvbrhplyuq/Build/Intermediates.noindex/App.build/Release-iphonesimulator/App.build/Objects-normal/arm64/Binary/App normal arm64
(3)先提交到git上,再打上tag版本号,再提交tag,这里的tag版本号要与.podspec文件中的spec.version一致
git tag -a 0.0.2 -m “my version 0.0.2”
git push origin 0.0.2
注意:先提交再打tag
(4)验证.podspec文件的正确性
pod spec lint QCXMyLogin.podspec --use-libraries --verbose --allow-warnings
将QCXMyLogin.podspec 替换成你的,–use-libraries是用到三方SDK时候需要加上,–verbose显示验证时的详细信息,–allow-warnings是允许警告的出现。
这个过程是Cocoapods会把代码的每个版本都要编译,都没有问题了才行。
此时验证时会出现各种各样的问题,后边我会总结一下。
验证成功是这样的
(5)通过trunk推送podspec文件
pod trunk push QCXMyLogin.podspec
QCXMyLogin.podspec替换成你的
这个时候会消耗一些时间,成功后是这样的
3.接下来就可以使用自己的私有库了
pod search QCXMyLogin
可能会找不到,报这个错
[!] Unable to find a pod with name, author, summary, or description matching QCXMyLogin
需要更新一下
pod repo update
使用就和其他的三方SDK一样了
三、问题总结
出现的问题
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.
解决方案:私有库的三方依赖用这种方式spec.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:
-> QCXMyLogin (0.0.2) - 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 QCXMyLogin (0.0.2)
[!] Unable to read the license file FILE_LICENSE
for the spec QCXMyLogin (0.0.2)
这个错误也是使用指令pod trunk push QCXMyLogin.podspec 检查文件是否合法时发生的;
这个是在指定共享的类库时, 文件路径不对, 也就是设置spec.source_files 字段时, 发生了错误, 这里的路径是相对于QCXMyLogin.podspec文件的, 如果是与QCXMyLogin.podspec同级的文件夹, 直接写文件夹名称即可, 如:
spec.source_files = “QCXMyLogin”
如果有多级目录, 一定要逐级添加. 这里也可以这么写:
spec.source_files = “QCXMyLogin/.{h,m}" //或者spec.source_files = "QCXMyLogin/”
error4:
Unable to interpret the specified path QCXMyLogin.podspec
as a podspec (Pod::DSLError).
podspec文件中有中文标点,仔细检查下😊
error5:
[!] Unable to read the license file FILE_LICENSE
for the spec QCXMyLogin (0.0.1)
本来默认生成的是: spec.license = { :type => “MIT”, :file => “FILE_LICENSE” }, 看错误的意思是找不到FILE_LICENSE这个文件,改成spec.license = { :type => “MIT”, :file => “LICENSE” }就好了,这个错误要多试下,看其他文章有不通的解决方法,可能是和环境有关系。
error6:
[!] Unable to accept duplicate entry for: QCXMyLogin (0.0.1)
字面意思是不能接受重复输入,修改podspec文件中spec.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 并保存
上传的demo(QCXMyLogin)
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:
发布自己的SDK后,无法搜索到,提示错误:
Unable to find a pod with name, author, summary, or description matching ‘xxx’
用了各种方式都不行,最后用的是这几步:
pod repo remove master
cd ~/.cocoapods/repos
git clone --depth 1 https://github.com/CocoaPods/Specs.git master // 这一步下载的特别慢,最好是用VPN快一些
之后就能搜到了
error12:
在验证时出现这个错误:
一般是网络原因导致的,等网好了再试试
error13:
出现这个错误:
Ld /Users/xxx/Library/Developer/Xcode/DerivedData/App-bwkbveecivxcorfbcyxvcxznzwsm/Build/Intermediates.noindex/App.build/Release-iphonesimulator/App.build/Objects-normal/x86_64/Binary/App normal x86_64
可以在验证和发布的后边加上 --skip-import-validation
error14:
当pod search xxx
时可以找到最新的SDK,pod install
无法找到最新的SDK时
可以执行:pod repo update
之后再执行 pod install
,或者直接执行 pod install --repo-update
问题持续更新中…