0
点赞
收藏
分享

微信扫一扫

iOS 组件化 私有库(一)创建本地私有库

cocoapods 组件化 私有库 spec文件 Library not found for -l

为什么要有组件化

  • 一个公司的项目在不断更新迭代,项目代码越来越复杂,模块间的耦合度越来越高,导致我们后续的开发成本越来越大
  • 引入组件化是为了降低模块间的耦合,提高开发效率

组件化的创建过程

1、创建本地文件夹

在项目根目录中,创建文件夹,专门存放本地的业务模块。然后在文件夹中创建相应的业务模块文件夹。

2、创建​​podspec​​文件

cd到该业务模块下,创建podspec文件

pod spec create CLCNTalker

创建pod索引库,固定写法,并且定义索引库的名字为s,后续通过s,就能拿到索引库 Pod::Spec.new do |s| // 设置名称 s.name = "tcggMain" // 设置版本号 s.version = "0.0.1" // 设置摘要 s.summary = "A short description of tcggMain." // 设置详情 s.description = "Good" // 设置仓库主页 s.homepage = "http://xxxx/xxxx" // 设置许可证 s.license = "MIT" // 设置作者 s.author = { "iThinkerYZ" => "xxxx@qq.com" } // 设置仓库源,表示在哪可以找到组件工程 s.source = { :git => "xxxxx", :tag => "#{s.version}" } // 设置 源文件路径 => 不是整个工程的文件,而是自己封装的代码,以后别的工程引入,就会引入这里的代码。 s.source_files = "tcggMain/Classes/**/*.{h,m}" // s.dependency = '' 组件工程依赖哪些第三方框架 // s.frameworks = 'UIKit', 'MapKit' 组件工程依赖哪些原生框架 // s.resource_bundles = {} 组件工程图片资源 end

私有库制作过程中一定会遇到各种各样的问题,笔者把一些常见的问题及解决方案罗列了一下,仅供参考~

1)、如果私有库中用到了C++类库,一定要在spec文件中配置如下内容

s.libraries = 'c++', 'z'

2)、如果报了如下归档、解档错误,可能是libopencore-amrnb音频转换库和libopencore-amrwb语音录制包没有导入,如果导入了,再检查下vendored_libraries路径配置的是否正确

ld: warning: directory not found for option '-L/Users/zhanghb/Documents/workspace/NTalker1213/Example/**.framework'

Undefined symbols for architecture x86_64:

  "_Decoder_Interface_init", referenced from:

      DecodeAMRFileToWAVEFile(char const*, char const*) in CLCNTalker(amrFileCodec.o)

  "_Decoder_Interface_Decode", referenced from:

      DecodeAMRFileToWAVEFile(char const*, char const*) in CLCNTalker(amrFileCodec.o)

  "_Decoder_Interface_exit", referenced from:

      DecodeAMRFileToWAVEFile(char const*, char const*) in CLCNTalker(amrFileCodec.o)

  "_Encoder_Interface_init", referenced from:

      EncodeWAVEFileToAMRFile(char const*, char const*, int, int) in CLCNTalker(amrFileCodec.o)

  "_Encoder_Interface_Encode", referenced from:

      EncodeWAVEFileToAMRFile(char const*, char const*, int, int) in CLCNTalker(amrFileCodec.o)

  "_Encoder_Interface_exit", referenced from:

      EncodeWAVEFileToAMRFile(char const*, char const*, int, int) in CLCNTalker(amrFileCodec.o)

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

3)、如果本地库中引用了.a文件,一定要将.a文件以lib开头重命名,否则编译报错,会报Library not found for -lxxx

4)、Multiple commands produce …… Assets.car…… 这个问题的解决方案是在profile文件中加上install! 'cocoapods', :disable_input_output_paths => true这句

5)、bundle文件一定要放在Assets文件夹中,否则在xcode左侧的工程目录无法正常显示

6)、spec文件每次改动后,都要重新执行一次pod install

3、新建​​LICENSE​​文件

4、添加类文件、资源文件

将类文件、资源文件拖到对应的文件夹下面即可

5、vendored_libraries和resources的配置需要注意一下,pod install 后的目录结构

6、当其他模块引用先创建的本地私有库时仅需要在当前模块的spec文件中加入将要引入的库



举报

相关推荐

0 条评论