一、CocoaPods 简单快捷的创建私有库

前言

网上看了很多的私有库创建,经过一大堆弯弯绕绕的命令,最后都会存这个问题([!] An unexpected version directory Classes)。所以写此文章记录一下。

一、创建远程仓库

个大仓库均可任选其一,本文以码云为例

仓库创建注意事项:

1、创建前,先确认仓库名称是否被占用

pod search XCTest

如上,没有找到相关的库,说明该库没有被占用,我们可以使用这个库名。

2、填写仓库名称和描述即可直接创建仓库

3、通过工具SourceTree在本地,如果拉取后有分支,可以创建一个main分支,并进入码云仓库管理页面设置默认分支为main分支。如果不能创建就到第六步在执行也没有有关系(我这里没有选择分支模版,所以把分支创建放在第六步创建,如果选择了分支模版到,默认有master分支,可以在这里直接创建一个main分支)。main分支作用是作为你私有库到索引,所以要设置为默认分支。

二、创建工程项目

项目名称与仓库名称一致

pod lib create XCTest
Cloning `https://github.com/CocoaPods/pod-template.git` into `XCTest`.
Configuring project template.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide:
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and click links to open in a browser. )
What platform do you want to use?? [ iOS / macOS ]
 >
ios
What language do you want to use?? [ Swift / ObjC ]
 >
swift
Would you like to include a demo application with your library? [ Yes / No ]
 >
yes
Which testing frameworks will you use? [ Quick / None ]
 >None

Would you like to do view based testing? [ Yes / No ]
 > No

执行完上面命令后XCode会自动打开项目,创建完成后不用管,关闭项目,将项目复制到库文件夹里,注:如果设置有显示隐藏文件夹的,勿复制.git文件夹

三、配置.podspec文件

进入刚刚复制的文件夹内打开Example项目,结构如下

image.png

重要配置如下

s.homepage         = 远程仓库地址
s.source           = 远程仓库git地址
s.swift_version    = '4.0'

其余配置根据实际需求进行配置修改

四、验证

打开终端cd到仓库目录(Example上层目录)

pod lib lint --allow-warnings

 -> XCTest (1.0.0)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | url: There was a problem validating the URL https://gitee.com/xxxx/xxxx.
    - WARN  | [iOS] swift: The validator used Swift `4.0` by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_versions` attribute in your podspec. Note that usage of a `.swift-version` file is now deprecated.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

XCTest passed validation.

验证成功

五、上传代码到仓库

1、这里不多描述,重点打tag,重点打tag,重点打tag,重要打事情说三片。tag与配置文件的版本一致

2、远程验证

pod spec lint --allow-warnings

 -> XCTest (1.0.0)
    - WARN  | summary: The summary is not meaningful.
    - NOTE  | url: The URL (https://gitee.com/xxxx/xxxx) is not reachable.
    - WARN  | [iOS] swift: The validator used Swift `4.0` by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_versions` attribute in your podspec. Note that usage of a `.swift-version` file is now deprecated.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

Analyzed 1 podspec.

XCTest.podspec passed validation.

六、创建分支

1、由于我创建仓库有区别,所以在拉下库的时候没有任何分支,所以这里创面main分支后里面只保留README文件,其余全部删除。提交到代码库,请勿合并到master、提交到代码库,请勿合并到master、提交到代码库,请勿合并到master,重要到事情说三片。然后就不在管main分支。

2、进入码云仓库管理页面设置默认分支为main分支,默认分支很重要,默认分支很重要,默认分支很重要说三片

七、将远程端私有索引库(Repo)添加到本地的

pod repo add XCTest https://gitee.com/xxxx/xxxx.git

执行完成后,进入文件~/.cocoapods/repos,查看文件结构如下

image.png

八、提交到远程端私有索引库

pod repo push XCTest XCTest.podspec --allow-warnings

Validating spec
 -> XCTest (1.0.0)
    - WARN  | summary: The summary is not meaningful.
    - NOTE  | url: The URL (https://gitee.com/xxxx/xxxx) is not reachable.
    - WARN  | [iOS] swift: The validator used Swift `4.0` by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_versions` attribute in your podspec. Note that usage of a `.swift-version` file is now deprecated.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

Updating the `XCTest' repo


Adding the spec to the `XCTest' repo

 - [Add] XCTest (1.0.0)

Pushing the `XCTest' repo

九、最后见证奇迹一刻

再次搜索库名

pod search XCTest
-> XCTest (1.0.0)
   A short description of XCTest.
   pod 'XCTest', '~> 1.0.0'
   - Homepage: https://gitee.com/xxxx/xxx
   - Source:   https://gitee.com/xxxx/xxx.git
   - Versions: 1.0.0 [XCTest repo]

好了你要的私有库已经创建完成,任意一个项目在Podfile配置如下:

source 'https://gitee.com/xxxx/xxx.git'
platform :ios, ’9.0’

target 'Test' do
 pod 'XCTest'

end

进入到项目里面执行命令

pod install
或者
pod install --repo-update

即可在项目里面使用你私有库了。下一篇将学习文件、资源文件的使用和版本更新

猜你喜欢

转载自juejin.im/post/6999830025084076039