美文网首页
四、远程私有库的升级+依赖+分支+资源依赖+xx_prefix.

四、远程私有库的升级+依赖+分支+资源依赖+xx_prefix.

作者: lrxxhyf | 来源:发表于2018-01-11 09:37 被阅读256次
打造远程私有库的步骤

一、远程私有库的升级

  1. 首先把升级的源代码拖到Classes文件夹里面
  2. 进入到测试工程pod install安装好测试代码
$ cd /远程私有库方案/RemoteLib/LRSoundBase2/Example 
$ pod install
  1. 将.spec文件里面的版本号进行修改 , s.version = '0.2.0'
  2. 将本地私有库所有文件提交到远程私有库中
$ cd /远程私有库方案/RemoteLib/LRSoundBase2 
$ git add .
$ git commit --m '增加了基础配置和工具类'
$ git push origin master
  1. 根据描述文件的版本号,打上对应的tag值
$ git tag '0.2.0'
$ git push --tags
  1. 做好两步验证,验证.spec文件的合法性
$ pod lib lint --allow-warnings
$ pod spec lint --allow-warnings
  1. 将.spec文件提交到本地的私有索引库中,本地私有索引库会自动同步到远程私有索引库中
$ pod repo push LRSoundSpec2 LRSoundBase2.podspec

8.回到宿主工程中,将podfile.lock删除,使用pod install安装最新pod库

$ cd /远程私有库方案/LRSound 
$ pod install

二、远程私有库的升级+依赖

场景:我们在升级私有库的时候,有些时候可能会用到其他的第三方框架,这个时候我们一般会对第三方框架做一个二次封装,那么我们如果要将二次封装的代码放到我们的私有库当中,我们就需要做依赖。

  1. 我们将要升级的代码拖入到Classes文件夹下面
  2. 进入到测试工程pod install安装到测试代码
  3. 需要将.spec文件做一个修改,主要是版本号和依赖关系
s.version = '0.3.0'
s.dependency 'AFNetworking'
  1. 提交本地代码仓库到远程代码仓库,并且打上和描述文件一一对应的tag值
  2. 做好两步验证,上传.spec文件到远程索引库
  3. 回到宿主工程中,使用 pod update 或者 将podfile.lock删除,使用pod install安装最新pod库

三、远程私有库分支 + 依赖

  1. 我们检查一下Classes文件夹下面的库是否完整


    Classes
  2. 修改我们的spec文件sourc_files属性,扩展子库的文件路径,添加依赖,并且修改版本号

  s.version = '0.4.0'

  s.subspec 'Category' do |c|
    c.source_files = 'LRSoundBase2/Classes/Category/**/*'
  end

  s.subspec 'Network' do |n|
    n.source_files = 'LRSoundBase2/Classes/Network/**/*'
    n.dependency 'AFNetworking'  #将依赖添加到分支上
  end

  s.subspec 'Tool' do |t|
     t.source_files = 'LRSoundBase2/Classes/Tool/**/*'
  end

# 需要注释掉 s.source_files ,否则会冲突
# s.source_files = 'LRSoundBase2/Classes/**/*'  
  1. 提交本地私有库的代码到远程私有库中
  2. 对spec文件做好两步验证
  3. 提交spec文件到本地索引库和远程索引库中
    如果在 pod repo push 时提示 The repo ’LRSoundSpec2’ at ‘/.cocoapods/repos/LRSoundSpec2‘ is not clean,解决办法如下:
# 先提交一下远程私有库,再提交spec文件到本地索引库和远程索引库
$ cd /Users/admin/.cocoapods/repos/LRSoundSpec2
$ git add .
$ git commit --m 'xx'
$ git push
$ cd /远程私有库分支/RemoteLib/LRSoundBase2
$ pod repo push LRSoundSpec2 LRSoundBase2.podspec
  1. 回到宿主工程中安装所需要对应的分支库
source 'https://gitee.com/lrskey/LRSoundSpec2.git'
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'

target 'LRSound' do
  use_frameworks!

  pod 'LRSoundBase2/Tool'
  pod 'LRSoundBase2/Network'

end

四、远程索引库资源依赖

  1. 首先检查源代码的完整性
  2. 将源代码扔到Classes文件夹下面
  3. 如果源代码中有XIB这类型的资源,我们需要找到对应的bundle路径,重新指明bundle路径,修改之前使用的mainBundle路径。

加载 Xib 文件:

+ (instancetype)middleView {
    
    NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
    TZMiddleView *middleView = [[currentBundle loadNibNamed:@"TZMiddleView" owner:nil options:nil] firstObject];
    return middleView;
}

五、远程索引库图片依赖

  1. 首先检查源代码的完整性
  2. 将需要集成到私有库的图片资源扔到Assets文件夹下面,并且修改 spec 文件中的资源文件路径,安装到 Example 测试工程


    添加图片资源到 Assets
 s.resource_bundles = {
   'LRSoundMain1' => ['LRSoundMain1/Assets/*.png']
 }

products -> LRSoundMain1_example.app -> show in finder -> 显示包内容 -> Assets.car (图片资源文件)

  1. 其他需要使用的图片资源还是放在测试工程中的图片资源文件夹下面


    添加其他图片到宿主工程
  2. 如果说有使用到xib或者storyBoard的地方需要加载图片,需要在使用图片的地方指明存放图片资源的bundle路径。

products -> LRSoundMain1_example.app -> show in finder -> 显示包内容 -> Frameworks -> LRSoundMain1.framework -> LRSoundMain1.bundle

xib 图片资源的路径
  1. 在给控件设置图片的位置,需要去指明图片资源存放的bundle路径,图片的类型以及分辨率都要指明,否则图片加载不了。
    //不在 mainBundle 里面加载图片,必须添加后缀名和分辨率,否则加载不出来
    NSBundle *currentBuddle = [NSBundle bundleForClass:[self class]];
    NSString *imagePath = [currentBuddle pathForResource:@"tabbar_bg@2x.png" ofType:nil inDirectory:@"LRSoundMain1.bundle"];
    UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
  1. 修改 spec 文件,提交spec文件到本地索引库和远程索引库中

  2. 回到宿主工程中安装所需要对应的分支库

六、设置框架中 xx-prefix.pch 文件,导入公共头文件,通过修改 spec 文件中的prefix_header_contents属性

s.prefix_header_contents = '#import "const.h"','#import "macro.h"'

相关文章

网友评论

      本文标题:四、远程私有库的升级+依赖+分支+资源依赖+xx_prefix.

      本文链接:https://www.haomeiwen.com/subject/ywsdbxtx.html