iOS 将自己的SDK用Cocoapods管理 (用到三方SDK,资源文件)

7 篇文章 0 订阅

一、准备工作

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


问题持续更新中…

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值