podspec相关设置, 及其私有库常见错误记录

.

podspec相关设置

s.source_files = 'SignatureModule/Classes/**/*.{h,m,mm}'
需要编译的代码文件目录,
如果文件层级达到3级, 需要改SignatureModule/Classes/**/**/*, 再更多层级, 依次类推添加**
s.resources = 'SignatureModule/Classes/data.bundle'
bundle文件目录
s.prefix_header_file = 'SignatureModule/Classes/SignatureModule.h'
pch文件
s.vendored_libraries = 'SignatureModule/Classes/**/*.{a}'
自己的.a静态库文件目录
s.frameworks = 'UIKit', 'Foundation', 'CoreLocation', 'SystemConfiguration', 'Accelerate'
引入系统的frameworks
s.library = 'stdc++'
引入系统的library
s.dependency 'iOS-ProgressHud',        '~> 1.0.0'
设置需要依赖的第三方
s.resource_bundles = {
  'SignatureModule' => ['SignatureModule/Assets/[email protected], #SignatureModule/Assets/[email protected]']
 }
图片资源文件路径
s.requires_arc = true
设置为arc

s.requires_arc = false
s.requires_arc = 'Classes/Arc'
s.requires_arc = ['Classes/*ARC.m', 'Classes/ARC.mm']
部分文件设置为arc
s.subspec 'AlertView' do |ss|
  ss.dependency 'iOS-Tools/HexColors'
  ss.dependency 'AFNetworking',        '~> 3.0.0'
  ss.source_files = 'iOS-Tools/AlertView/*.{h,m}' 
  ss.public_header_files = 'iOS-Tools/AlertView/GFBCustomAlertView.h'
end
制作subspec, 被导入是可以显示出良好的文件层划分
注: subspecA依赖subspecB, dependency 后面接的specA/specB, 而不是文件路径
    引用AFNetworking这种公共库, 使用上述方式就可以
s.xcconfig = {
  'ENABLE_BITCODE' => 'NO',
  'CLANG_CXX_LIBRARY' => 'libstdc++'
  }
buildsetting相关设置, 这里讲bitcode设置为NO, C++ Standard Library设置为libstdc++

Cocoapod提供了一些buildsetting的相关变量配置, 若官方没有提供, 可以使用下述方法:
在buildsetting中选中需要修改的配置项

image.png

command + C 进行复制, 如图所示, 复制出来的是:

//:configuration = Debug
//:configuration = Release
//:completeSettings = some
ENABLE_INCREMENTAL_DISTILL

我们需要将此选项设置为YES, 添加如下代码即可

s.xcconfig = {
  'ENABLE_INCREMENTAL_DISTILL' => 'YES'
  }

其他更多使用方法, 可以详见官方文档:https://guides.cocoapods.org/syntax/podspec.html#header_mappings_dir

.

常见错误记录

私有库引用私有库进行验证

使用pod spec lint进行验证的时候, 会报找不到repo的错误, 需要添加sources选项

pod spec lint --sources='引用私有仓库的repo地址, https://github.com/CocoaPods/Specs'

使用pod repo push时, 同样也需要添加sources选项

pod repo push 本地索引库名 podspec名 --sources='私有仓库repo地址,https://github.com/CocoaPods/Specs'

私有库引用问题

私有库引用别的库, 不能在.h文件中直接引用, 直接引用进行pod lib lint 或pod spec lint编译操作时, 会报错. 只能在.h中使用@class, 在.m中import

将图片资源文件打包成bundle, 引用问题

尽量将图片等资源打包成bundle文件, 这样有效的防止了资源文件命名的冲突, 引用方法

NSBundle *bundle = [NSBundle bundleForClass:["pod中随意一个类" class]];
NSURL *bundleURL = [bundle URLForResource:@"bundle文件名" withExtension:@"bundle"];
NSBundle *resourceBundle = [NSBundle bundleWithURL: bundleURL];
UIImage *img = [UIImage imageNamed:icon inBundle:bundle compatibleWithTraitCollection:nil];

先拿到该pod下随意一个类的bundle(该bundle与资源文件是一个bundle), 
再根据该bundle找到bundle资源文件的路径, 最后使用资源文件.

specification does not validate.

image.png
1. 后面添加 --allow-warnings, 警告过多, 会导致pod repo push报错

2. buildsetting没有设置好, 导致报错.
    添加了ss.pod_target_xcconfig = {'OTHER_LDFLAGS' => ['-lObjC', '-all_load']}之后, 可正常通过

subspecA引用subspecB问题

subspecA引用subspecB需要添加dependency
例如: ss.dependency 'iOS-Tools/NSString+Categories'
注意: ss.dependency后面跟的是依赖关系, 并不是文件目录路径

spec使用xib问题

xib文件算是资源文件的,需要另外添加 s.resource 引入, 通过 source_files 引入的话, 会报出如下的错误.
image.png
修正前
  s.source_files = "pod/classes/**/*"
修正后
s.source_files  = "pod/classes/**/*.{h,m}"
s.resource = "pod/classes/TestViewController.xib"

.

后遇坑会持续更新...

你可能感兴趣的:(podspec相关设置, 及其私有库常见错误记录)