利用Cocoapods创建公共组件

2019-08-10  本文已影响0人  Frankkkkk

背景

在开发过程中,由于某个子组件中的内部SDK需要经常变动,所以想把该内部SDK从子组件中抽离出来,作为独立的组件放到项目中,由此产生了创建公共组件的想法。下面以创建ALAMuDaoSDK组件为例

创建公共组件的步骤

一、创建本地组件库

1.查找是组件库是否被使用

pod search ALAMuDaoSDK

如果没找到,就放心用吧;如果已被使用,就换一个组件名字

2.创建本地组件库

cd  [文件夹目录]
pod lib create ALAMuDaoSDK

3.接下来,逐一回答问题

逐一回答问题

4.创建完毕,打开工程

项目结构.png

5.添加自己的文件
选中ReplaceMe.m—showInFinder进入文件目录,删除ReplaceMe.m文件,添加自己的文件,这里我添加了一个静态库,如下图所示:

添加自己的文件

**6.切到Example目录,然后pod install

加载自己的文件
安装完成后,目录如下:
工程目录
恭喜,你可以看到刚才加进去的文件了!

二、在github上创建远程仓库

1.按下图所示创建代码仓库

创建仓库
说明:

三、将本地代码推送到远程仓库(绑定仓库)

git add .
git commit -m "第一次提交"
git remote add origin https://github.com/xxx/xx.git
git push -u origin master

四、配置.podspec文件(这里不用配置版本)

  # s.source_files = 'ALAMuDaoSDK/Classes/**/*'
  s.vendored_frameworks = 'ALAMuDaoSDK/Classes/*.{framework}'
  s.resource = 'ALAMuDaoSDK/Assets/FanbeiCreditSDKResource.bundle'

注意:这里的目录都是相对ALAMuDaoSDK.podspec文件的

五、验证.podspec文件(初始化验证)

Frankkkk-2:AlAMuDaoSDK aladin$ pod lib lint

 -> ALAMuDaoSDK (0.1.0)
    - WARN  | description: The description is shorter than the summary.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file /Users/aladin/workspace/ala_mudao_sdk/ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture x86_64 in file /Users/aladin/workspace/ala_mudao_sdk/ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file /Users/aladin/workspace/ala_mudao_sdk/ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture i386 in file /Users/aladin/workspace/ala_mudao_sdk/ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)

[!] ALAMuDaoSDK did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
You can use the `--no-clean` option to inspect any issue.
Frankkkk-2:AlAMuDaoSDK aladin$ pod lib lint --allow-warnings

 -> ALAMuDaoSDK (0.1.0)
    - WARN  | description: The description is shorter than the summary.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file /Users/aladin/workspace/ala_mudao_sdk/ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture x86_64 in file /Users/aladin/workspace/ala_mudao_sdk/ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file /Users/aladin/workspace/ala_mudao_sdk/ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture i386 in file /Users/aladin/workspace/ala_mudao_sdk/ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)

ALAMuDaoSDK passed validation.

六、提交本地版本代码到Github,并打指定版本的tag

1.修改ALAMuDaoSDK.podspec的版本为0.1.1,s.version = '0.1.1'
2.提交到master,并打0.1.1版本的tag(该版本必须和s.version相同)。

Frankkkk-2:AlAMuDaoSDK aladin$ git add .
Frankkkk-2:AlAMuDaoSDK aladin$ git commit -m "版本0.1.1"
[master a54d31d] 版本0.1.1
 2 files changed, 17 insertions(+), 17 deletions(-)
Frankkkk-2:AlAMuDaoSDK aladin$ git push origin master
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 4 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 866 bytes | 866.00 KiB/s, done.
Total 7 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), completed with 5 local objects.
To https://github.com/WJLollipop/ALAMuDaoSDK.git
   4f6d866..a54d31d  master -> master
Frankkkk-2:AlAMuDaoSDK aladin$ git tag 0.1.1
Frankkkk-2:AlAMuDaoSDK aladin$ git push origin 0.1.1
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/WJLollipop/ALAMuDaoSDK.git
 * [new tag]         0.1.1 -> 0.1.1

七、验证新版本0.1.1是否可用

Frankkkk-2:AlAMuDaoSDK aladin$ pod spec lint ALAMuDaoSDK.podspec

 -> ALAMuDaoSDK (0.1.1)
    - WARN  | description: The description is shorter than the summary.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture i386 in file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture x86_64 in file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
Frankkkk-2:AlAMuDaoSDK aladin$ pod spec lint ALAMuDaoSDK.podspec --allow-warnings

 -> ALAMuDaoSDK (0.1.1)
    - WARN  | description: The description is shorter than the summary.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture x86_64 in file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture i386 in file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)

Analyzed 1 podspec.

ALAMuDaoSDK.podspec passed validation.

八、推送.podspec文件到trunk

Frankkkk-2:AlAMuDaoSDK aladin$ pod trunk push ALAMuDaoSDK.podspec --allow-warnings
Updating spec repo `master`

CocoaPods 1.8.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.8.0.beta.1

Validating podspec
 -> ALAMuDaoSDK (0.1.1)
    - WARN  | description: The description is shorter than the summary.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture x86_64 in file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)
    - NOTE  | [iOS] xcodebuild:  ld: warning: ignoring file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK, missing required architecture i386 in file ALAMuDaoSDK/ALAMuDaoSDK/Classes/FanbeiCreditSDK.framework/FanbeiCreditSDK (2 slices)

Updating spec repo `master`

CocoaPods 1.8.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.8.0.beta.1


--------------------------------------------------------------------------------
 🎉  Congrats

 🚀  ALAMuDaoSDK (0.1.1) successfully published
 📅  August 10th, 03:21
 🌎  https://cocoapods.org/pods/ALAMuDaoSDK
 👍  Tell your friends!
--------------------------------------------------------------------------------

到此,恭喜创建公开库成功!
查看地址:https://cocoapods.org/pods/ALAMuDaoSDK

九、搜索公开库

pod search ALAMuDaoSDK

注意:如果报以下错误:

Frankkkk-2:~ aladin$ pod search ALAMuDaoSDK
[!] Unable to find a pod with name, author, summary, or description matching `ALAMuDaoSDK`

删除~/Library/Caches/CocoaPods/目录下的search_index.json文件,重新搜索即可。

上一篇下一篇

猜你喜欢

热点阅读