Podfile文件
如何把target下面configuration中的预编译宏传递到pod管理的模块
通过自定义配置可以:
#遍历每个依赖target的配置
target.build_configurations.each do |config|
#宏传递时,主target也记得设置一下, 貌似cocoapods没啥手段直接设置主project的GCC_PREPROCESSOR_DEFINITIONS
if config.name == 'UAT' or config.name == 'AppStore' or config.name == 'Prod'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
'AppStore_ENV=1',
'SupressNSLog=1'
]
config.build_settings['VALID_ARCHS'] = 'arm64'
else
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
'AppStore_ENV=0',
'SupressNSLog=0'
]
config.build_settings['VALID_ARCHS'] = 'arm64 x86_64'
end
如何把pod 管理的三方库bitCode 编译关掉?
Podfile使用了一个 "post_install" Hooks,这个Hooks允许你在生成的Xcode project写入硬盘或者其他你想执行的操作前做最后的改动所以,我们可以这么操作(直接复制代码到podfile 执行pod install 会报错,代码要格式化一下)
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
use_frameworks
1、podfile文件的 不使用use_frameworks! -> static libraries 方式 -> 生成.a文件 2、podfile文件的 use_frameworks! -> dynamic frameworks 方式 -> 生成.framework文件
1)使用use_frameworks,在桥接文件里加上#import "AFNetworking/AFNetworking.h"
2)不使用frameworks,桥接文件加上 #import "AFNetworking.h"
根据不同的configuration 安装不同的pod 库
pod 'AvoidCrash', '~> 2.5.2.1009', :configuration => ['UAT', 'AppStore', 'PROD']
pod 批量修改target version
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
end
end
end
语法格式
1、pod 'OctoKit.swift' 中''里面的内容是.podspec文件的名字 2、pod 'OctoKit.swift', :path => './octokit.swift-main' path 是指.podspec文件 的路径
podspec 文件
设置这个仓库的依赖仓库
s.dependency 'FMDB', '~> 2.7.2'
设置这个仓库公开的头文件
s.public_header_files = 'ABC/*.h'
设置这个仓库的代码位置
#Classes目录下的所有文件
s.source_files = 'ABC/Classes/**/*'
设置这个仓库的资源文件位置
s.resource_bundles = {
'ABC' => [
'ABC/Assets/images/*.{png,jpg}',
'ABC/Assets/strings/*.lproj/*.strings',
'ABC/Assets/animation/*.json',
'ABC/Assets/xib/*.xib',
'ABC/Assets/images/categoresImage/*.{png,jpg}',
'ABC/Assets/xml/*.xml'
]
}
设置依赖的非系统框架
s.ios.vendored_frameworks = ["ABC/ABC.framework"]
设置依赖的系统框架
s.frameworks = 'UIKit', 'MapKit'
设置依赖的系统库
s.library = "stdc++"
设置依赖的非系统的静态库
s.vendored_libraries = 'BlueToothQinLinLib/Framework/libDHble.a
多平台指令exclude_files
s.ios.exclude_files = 'Classes/osx' #引用组件不包含Classes/osx下的文件
s.exclude_files = 'Classes/**/unused.{h,m}' #引用组件不包含Classes/**/unused.{h,m}下的
设置这个仓库prefix_header文件
s.prefix_header_contents = <<-EOS
#import <Masonry/Masonry.h>
EOS
podspec的子仓库设置
通过.subspec 可以为一个pod 仓库设置多个子仓库,每个子仓库可以可以像一个单独的pod仓库一样,设置依赖,设置sourceFile 设置 prefix_header等等。 每一个子仓库又可以设置多个子仓库。子仓库可以像父仓库一样,被单独依赖。 这样就很方便我们的SDK管理了。 假如有业务需求如下: 我们工程项目有很多SDK,有些SDK需要提供给其他第三方使用,比如SDKA。而有些第三方需要的是SDKA_FunctionA,有些需要SDKA_FunctionB,这样我们就需要把SDKA不同的Function 管理(因为可能FunctionA 和 FunctionB 依赖不同的三方库,而有些厂家已经集成了这些三方库,如果这样子他在集成SDKA的话就会有冲突(OC)),这个时候我们就可以用subspec 把一个仓库的不同功能隔离,之后他们SDKA/SDKA_FunctionA 或者SDKA/SDKA_FunctionB 就可以了。 下面给出以个具体的例子:
s.subspec 'Service' do |service|
service.subspec 'DeviceManager' do |deviceManager|
deviceManager.source_files = 'Bluetooth/Classes/Service/DeviceManager/**/*'
deviceManager.prefix_header_contents = $Bluetooth_prefix_header_contents
deviceManager.dependency 'moduleA'
deviceManager.dependency 'moduleB'
end
end
s.subspec 'Core' do |core|
core.prefix_header_contents = $Bluetooth_prefix_header_contents
core.source_files = 'Bluetooth/Classes/core/**/*'
core.dependency 'OpenSSL-Universal', '1.1.1100'
core.dependency 'moduleA'
core.dependency 'moduleC'
end
s.subspec 'Smart' do |smart|
smart.prefix_header_contents = $Bluetooth_prefix_header_contents
smart.source_files = 'Bluetooth/Classes/Smart/**/*'
smart.dependency 'moduleA'
smart.dependency 'moduleB'
smart.dependency 'moduleC'
smart.dependency 'MJExtension'
end
如果不需要源码依赖,可以把source_files 改成ios.vendored_frameworks = 'Framework_Path',前提是已经把pod 库做成framework