Post

podspec引入图片、宏定义、依赖库

前言

最近在研究Telegram代码,Telegram的代码是使用Bazel管理的,但是平常的项目都是使用Pod管理,于是将Bazel转换为pod依赖,过程中遇到很多问题,一一记录

问题一:项目库依赖项目写法

1.1 本地项目依赖本地项目,使用s.dependency "xxx"的语法

demo如下:本地项目LibA依赖本地项目LibB

1
2
3
4
5
6
7
Pod::Spec.new do |s|
    s.name = 'LibA'
    # ... 其他配置

    # 依赖测其他项目的名称
    s.dependency "LibB"
  end

被依赖的项目配置

1
2
3
4
Pod::Spec.new do |s|
    s.name = 'LibB'
    # ... 其他配置
  end

Podfile里的配置

1
2
3
4
5
6
7
platform :ios, '12.0'
use_frameworks!
target 'StudyAsynDisplay' do
  ## Pods for StudyAsynDisplay
  pod 'LibA', :path => 'xxx/xxxx/LibA'
  pod 'LibB', :path => 'xxx/xxxx/LibB'
end
1.2 本地项目依赖其他远程项目,使用s.dependency "xxx"的语法

demo如下:本地项目LibC依赖远程项目LibD

1
2
3
4
5
6
7
Pod::Spec.new do |s|
    s.name = 'LibC'
    # ... 其他配置

    # 依赖测其他项目的名称
    s.dependency "LibD"
end

Podfile里的配置

1
2
3
4
5
6
7
platform :ios, '12.0'
use_frameworks!
target 'StudyAsynDisplay' do
  ## Pods for StudyAsynDisplay
  pod 'LibC', :path => 'xxx/xxxx/LibC'
  pod 'LibD'
end

问题二:pod库引入xxx.bundlexxx.xcassets资源文件

1
2
3
4
5
6
7
8
9
Pod::Spec.new do |s|
    s.name = 'LibA'
    # ... 其他配置

    # 引入资源文件
    s.resource_bundle = {'XXX' => ['XXX/XXX.bundle']}
    # 也可以使用下面这种方式
    # s.resources = ['xxx/**/*.*', "yyyy/**/*.*", "ccc/*.xcassets"]
end

Multiple commands produce ‘…/xxx.app/Assets.car’问题 私有库使用Images.xcassets会出现Assets.car生成多次导致冲突的问题.

在Podfile第一行添加install! 'cocoapods', :disable_input_output_paths => true

1
2
3
4
5
6
7
8
install! 'cocoapods', :disable_input_output_paths => true
platform :ios, '12.0'
target 'StudyAsynDisplay' do
  use_frameworks!

  ## Pods for StudyAsynDisplay
  pod 'AsyncDisplayKit', :path => 'LocalLib/AsyncDisplayKit'
end

问题三:pod库引入xxx.axxx.framework静态库

1
2
3
4
5
6
7
Pod::Spec.new do |s|
    s.name = 'LibA'
    # ... 其他配置
    s.ios.vendored_libraries = 'xxxx/xxxx.a'
    s.static_framework = true
    # s.ios.vendored_frameworks = 'xxx/xxx.framework'
end

问题四:pod库引入宏设置

1
2
3
4
5
6
7
Pod::Spec.new do |s|
    s.name = 'LibA'
    # ... 其他配置
    s.pod_target_xcconfig = {
        'GCC_PREPROCESSOR_DEFINITIONS' => 'MyDefineA=1 MyDefineB=1'
    }
end

问题五,当引入了静态库后,会报编译不通过,将Podfile里的use_frameworks!改为use_frameworks! :linkage => :static

1
2
3
4
5
6
platform :ios, '12.0'
# use_frameworks!
use_frameworks! :linkage => :static
target 'StudyAsynDisplay' do
  ## Pods for StudyAsynDisplay
end

问题六,pod install时报

1
Specs satisfying the `xxxx (= x.x), xxxx` dependency were found, but they required a higher minimum deployment target.

platform :ios, '12.0'改高些比如platform :ios, '13.0',改完后pod install,然后再改回来成platform :ios, '12.0',之后再pod install

This post is licensed under CC BY 4.0 by the author.