IOS

cocoapods 私有库创建时遇到的问题

2018-04-09  本文已影响0人  春阳_fc96

        在创建 cocoapods 私有库时遇到很多坑,在网上找来找去超级麻烦,毕竟每个人遇到的问题都不一样。现在将我做的流程与遇到的坑整体都列出来,一是防止以后再遇到,二是希望能对遇到相同问题的有个帮助。很多具体的内容

主要参考:

1. https://www.jianshu.com/p/0c640821b36f

2.http://www.cocoachina.com/ios/20150228/11206.html

3.http://guides.cocoapods.org/syntax/podspec.html#specification

解决问题的主要途径:

stackoverflow

创建流程:

1. 创建私有Spec Repo

        1.1 首先创建一个 git 仓库(gitHub,Bitbucket,gitLab,coding,gitee,CSDN Code),权限选择私有仓库。如果有MIT选项,选中。

        1.2 将远程版本库添加到本地:pod repo add MyRepo https://xxx.git (创建好的Repo仓库)

        repo 是 repository (仓库)的缩写。其中 MyRepo 就是个人的私有版本库,名称可以自己定义。

        1.3 成功执行完上一步后, 在 finder 跳转到 ~/.cocoapods/repos 目录下可以看到MyRepo版本库。可以看到与 MyRepo 同级有一个 Master 版本库,这个是git默认的开源版本库。

2. 创建代码库

        2.1 同1.1

        2.2 可以使用常规创建项目方法, 将远程代码库添加到本地:git clone xxx.git TestCode,切换到该文件夹路径下

            2.2.1 创建项目 

            2.2.2 创建 .podspec 文件:$ pod spec create 项目名

            2.2.3 创建 .swift-version:  $ echo"2.3"> .swift-version

        2.3 也可以使用 $ pod lib create TestCode 创建

            2.3.1 创建项目

            2.3.2 选择相关信息:平台 、 语言 、 Demo 、 测试框架 、 界面测试 、 类前缀,根据需求选择。

            2.3.3 添加git :$ git remote add origin http://xxx.git

            2.3.4 拉取更新:$ git pull origin master --allow-unrelated-histories 也是与远程库产生联系

        2.4 修改 .podspec 文件: 

        Pod::Spec.new do |s|

          s.name        = "TestCode" # 项目名称

          s.version      = "0.0.1"        # 版本号 与 你仓库的 标签号 对应

          s.license      = { :type => "MIT", :file => "LICENSE" } # 开源许可证

          s.summary      = "desc" # 项目简介

          s.homepage    = "http://git.com/xxx" # 仓库的主页

          s.source      = { :git => "http://git.com/xxx.git", :branch => 'master', :tag => "#{s.version}" } #你的仓库地址,不能用SSH地址

          s.source_files = "TestCode/*.{h,m}" #  代码的位置

          s.requires_arc = true # 是否启用ARC

          s.platform    = :ios, "7.0" #平台及支持的最低版本

          # s.xcconfig = { 'OTHER_LDFLAGS' => '-Objc -all_load -fobjc-arc' ,'ENABLE_BITCODE'  => 'NO'} # target的相关设置

          s.author            = { "author" => "xxx.com" } # 作者信息, 开源上线后可能发送邮件

          # s.frameworks  = "UIKit", "Foundation" #支持的框架

          # s.resources    = "*.bundle" # 资源文件

          # s.dependency  = "AFNetworking"  # 依赖库,有多少依赖库就写多少 s.dependency

          # s.dependency 'AFNetworking',  '~> 3.0'  # 可以指定版本

        2.5 需要添加resource 则取消 s.resources 注释,在Assets加入资源并执行 pod install

        2.6 验证 .podspec 是否正确  pod lib lint 

        如果报警告而不是错误,可以使用  pod lib lint  --allow-warnings

        2.7 通过后显示 TestCode passed validation.

3. 上传代码

        3.1 修改代码完成后,修改项目中的版本与.podspec中的s.version版本

        3.2 pod lib lint  // 检查.podspec及代码是否有错误,如果有错误不能提交

               git add .  // 缓存修改

               git commit -m "desc" // 标记

               git tag "新的版本号" // 打标签

               git push --tags // 推送到远程仓库 (git push origin master --tags)

               pod repo push MyRepo TestCode.podspec // 修改版本仓库

        3.3 如果没有报错则全部提交成功

4. 使用私有库

        4.1 使用时需要在Podfile顶部中加入: 

        source 'https://xxx/MyRepo.git'

        source 'https://github.com/CocoaPods/Specs.git'    

        4.2 在podfile中引入需要使用的私有库,然后正常使用

遇到的问题:

验证仓库是否正确时

$ pod lib lint

1. 报错:description: The description is empty.

在 podspec 文件中 s.description 没有内容,如果不需要,那么注释掉

2. 报错:file patterns: The 'source_files' pattern did not match any file.

在 podspec 文件中 s.source_files 文件路径有误,这个路径是相对 .podspec 文件的,如果是与 .podspec 同级别的, 那么只需要写文件夹名称即可

s.source_files = "文件夹"

如果有多级,要完全按照路径来写

s.source_files = "文件夹/*.{h, m}"

s.source_files = "文件夹/**/*.{h, m}"

或者直接使用

s.source_files = "文件夹"

3. 报错:unknown: Encountered an unknown error (/usr/bin/xcrun simctl list -j devices

xcrun: error: unable to find utility "simctl", not a developer tool or in PATH) during validation.

原因是 Xcode 模拟器找不到,需要获取 Xcode 路径。

sudo xcode -select -switch /Applications/Xcode9.app/Contents/Developer

(常规路径是这个,即 Xcode 在应用程序中。如果不在或者有多个 xcode 需要根据修改 xcode 的路径)

4. 报错:license: Unable to find a license file

创建私人仓库时, 在验证时可能会找不到 MIT LICENSE证书。将 s.license ="MIT" 修改为,指定文件s.license = { :type=>"MIT", :file=>"LICENSE"}

如果是本身就没有MIT LICENSE证书,可以创建一个文件,命名为LICENSE。内容为:

Copyright (c) 20XX-20XX TestCode Software Foundation (http://XXX)Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 INTHE SOFTWARE.

将文中的时间、项目名与地址替换掉即可。

5. 报错:warning: Could not find remote branch 版本号 to clone. fatal: Remote branch 版本号 not found in upstream origin.

可能是s.version 与git tag版本号不一致、没有上传版本号或者git push 的时候没有添加--tags。

6. 如果报警告错误又不想处理可以使用 $ pod lib lint --allow-warnings 验证

7.报错:[!] The repo `MyRepo` at `../../../../.cocoapods/repos/MyRepo` is not clean

执行:$ pod repo update MyRepo

再次执行更新命令,如果还不可以那么先删除原有的版本库再重新安装版本库,然后执行更新命令

$ pod repo remove MyRepo

$ pod repo add MyRepo https://xxx.git 

$ pod repo push MyRepo XXX.podspec

8.报错:[!] The `xxx.podspec` specification does not validate. 但是没有ERROR

执行:pod repo push MyRepo xxx.podspec --verbose --use-libraries --allow-warnings

9.报错: ERROR | [iOS] unknown: Encountered an unknown error (undefined method `path' for nil:NilClass) during validation.

将 .podspec 中 s.source_files = 'Pod/Classes/**/*’ 改为 s.source_files = 'Pod/Classes/**/*.{c,h,hh,m,mm}'

10. 报错: fatal error: could not build module 'CoreFoundation'

见了鬼了,pod lib lint 检测到 pod spec lint 检测全都正确,结果到pod repo push MyRepo xx.podspec 时遇到了这个问题,还不是在正常的输入里显示,而是在很上面的日志中提示的,有很多,包括 Foundation。

将 .podspec 中 s.frameworks = 'UIKit', 'Foundation', 'CoreFoundation' 再次提交后上传。

需要添加资源

执行 pod install 添加 bundle

上一篇下一篇

猜你喜欢

热点阅读