iOS 常规ios收藏

创建私有库

2019-03-14  本文已影响54人  sky_fighting

在GitHub上创建私有库,并使用cocoapods导入使用

1、创建索引库

1)如下图所示 远程索引库 2)创建成功,此时包含如下图所示文件 远程索引库初始页面

1)首先使用pod repo查看当前的本地索引库

目前已有的本地索引库 2)创建本地索引库,使用$ pod repo add afSpecs https://github.com/afhappy/afSpecs.git进行本地索引库与远程索引库的关联
image.png 3)前往文件夹~/.cocoapods查看本地索引库地址
本地索引库路径

2、创建代码库

1)与创建远程索引库步骤相同,代码库名称为afShareSDKManage
2)创建结果页面如下图所示

远程代码库结果页面

1)打开终端,cd到需要存储本地库的路径下,使用pod lib create 本地库名称进行创建

创建本地代码库 2)查看本地代码库路径下文件,将自己封装好的类文件放到afShareSDKManage->afShareSDKManage->Classes目录下,资源文件存放在afShareSDKManage->afShareSDKManage->Assets目录下
image.png 3)打开终端,cd到afShareSDKManage->Example中,执行pod install安装新添加的文件 安装文件 4)编译Example成功后,修改afShareSDKManage.podspec索引文件
需要注意的几点:
1、版本号
2、项目的简单概述和详细描述
3、homepage和source地址
4、添加依赖库(可根据自己需要添加)
5、s.resource_bundles填写资源文件的路径,例如图片、xib、本地化等等
具体修改如下图所示: 索引文件修改信息

3、提交代码库

打开终端,cd到Example所在的文件目录下,执行如下命令
git add .
git commit -m "xxx"
git remote add origin 远程代码库地址
git push origin master   
git tag 版本号(与afShareSDKManage.podspec文件中版本号保持相同)
git push --tags

4、索引文件

使用pod spec lint --use-libraries --allow-warnings对索引文件进行验证,其中--use-libraries是由于项目中引用了shareSDK中含有framework,--allow-warnings是忽略警告的

验证索引文件

使用pod repo push 本地索引库 索引文件名 --use-libraries --allow-warnings提交索引库,例如:

pod repo push afSpecs afShareSDKManage.podspec --use-libraries --allow-warnings
提交索引库成功

5、测试

1)在桌面创建一个名为TestShareSDK的项目,使用pod init创建Podfile文件,在Podfile文件中引入索引库路径以及私有库,如下所示:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'   #公共源
source 'https://github.com/afhappy/afSpecs.git'     #私有源
target 'TestShareSDK' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for TestShareSDK
    pod 'afShareSDKManage', '~> 0.2.2'  #私有库
end

2)然后执行pod install安装

6、遇到的问题

出现The 'Pods-afShareSDKManage_Example' target has transitive dependencies that include static binaries: (~/Example/Pods/mob_sharesdk/ShareSDK/Support/Required/ShareSDKConnector.framework)问题,是由于静态库引起的
解决办法如下:
afShareSDKManage.podspec索引中,添加依赖之前,加上s.static_framework = true便可以解决

s.static_framework = true
s.dependency 'mob_sharesdk'
s.dependency 'mob_sharesdk/ShareSDKPlatforms/QQ'
s.dependency 'mob_sharesdk/ShareSDKPlatforms/SinaWeibo'
s.dependency 'mob_sharesdk/ShareSDKPlatforms/WeChat'
s.dependency 'mob_sharesdk/ShareSDKUI' # 分享弹窗或分享编辑页面
s.dependency 'mob_sharesdk/ShareSDKExtension'

如果出现类似error: failed to push some refs to 'https://github.com/afhappy/afShareSDKManage.git'错误时,是由于本地代码库和远程代码库存在冲突
解决办法如下:

$ git push -u origin master -f

出现Unable to find a pod with name, author, summary, or description matching "afShareSDKManage"
解决办法如下:

前往~/Library/Caches/CocoaPods文件夹,删除search_index.json文件,再次执行pod search afShareSDKManage,即可解决

结果如下图: 搜索结果

1)出现[!] Unable to determine Swift version for the following pods: "afShareSDKManage" does not specify a Swift version and none of the targets ("TestShareSDK") integrating it have the "SWIFT_VERSION" attribute set. Please contact the author or set the "SWIFT_VERSION" attribute in at least one of the targets that integrate this pod.
解决办法如下:

在创建私有库时,afShareSDKManage.podspec中添加swift的版本信息,例如:s.swift_version = '4.0'

2)出现类似[!] Unable to find a specification for `mob_sharesdk` depended upon by `afShareSDKManage`
解决办法如下:

pod repo remove master
pod setup

3)出现[!] An unexpected version directory `Classes` was encountered for the `/*/*/.cocoapods/repos/afhappy/afShareSDKManage` Pod in the `afShareSDKManage` repository.或者[!] An unexpected version directory `Assets` was encountered for the `/*/*/.cocoapods/repos/afhappy/afShareSDKManage` Pod in the `afShareSDKManage` repository.类似问题
解决办法如下:

按照指定路径删除对应文件即可,如上问题,就前往到/*/*/.cocoapods/repos/afhappy/afShareSDKManage目录下,删除Classes以及Assets即可

上一篇 下一篇

猜你喜欢

热点阅读