xcode 在 cocoapods podspec 文件中定义头搜索路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21132540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Define header search path in cocoapods podspec file
提问by Denis Loh
I have an issue with the definition of my podspec file for the framework I created. I have the following file structure:
我对我创建的框架的 podspec 文件的定义有问题。我有以下文件结构:
/
|-- module1/<source files>
|-- module2/<source files>
...
|-- moduleN/<source files>
|-- core-api/
| |-- module1/<header files>
| |-- module2/<header files>
| ...
| +-- moduleN/<header files>
|-- framework.podspec
+-- framework.xcodeproj
In XCode I added $(SRCROOT)/core-api
to the USER_HEADER_SEARCH_PATHS
so that Xcode can find the public header files correctly.
在 XCode 中,我添加$(SRCROOT)/core-api
到USER_HEADER_SEARCH_PATHS
以便 Xcode 可以正确找到公共头文件。
My podspec file looks like this:
我的 podspec 文件如下所示:
s.default_subspec = 'module1'
s.subspec 'module1' do |ss|
ss.source_files = "module1/**/*.{h,m}"
end
s.subspec 'module2' do |ss|
ss.source_files = "module2/**/*.{h,m}"
end
...
s.subspec 'moduleN' do |ss|
ss.source_files = "moduleN/**/*.{h,m}"
end
Currently, there are no directives which define the header location for the core-api. When I do pod lib lint
I get errors that the corresponding core-api headers weren't found.
目前,没有定义 core-api 头位置的指令。当我这样做时,pod lib lint
我收到找不到相应核心 API 标头的错误。
I was messing around with ss.header_dir
, ss.header_mapping_dir
, s.xcconfig
with USER_HEADER_SEARCH_PATH
, but none of them worked for me.
我在搞乱ss.header_dir
, ss.header_mapping_dir
, s.xcconfig
with USER_HEADER_SEARCH_PATH
,但没有一个对我有用。
How do I define the location of the header files in a podspec file correctly?
如何正确定义 podspec 文件中头文件的位置?
EDIT1:
编辑1:
I re-created the spec file from scratch and found out, that it seems to be necessary to add the core-api header files in each sub spec.
我从头开始重新创建规范文件,发现似乎有必要在每个子规范中添加 core-api 头文件。
My spec file looks now like this:
我的规范文件现在看起来像这样:
s.default_subspec = 'module1'
s.subspec 'module1' do |ss|
ss.public_header_files = "core-api/module1/*.h"
ss.source_files = "module1/**/*.{h,m}"
end
s.subspec 'module2' do |ss|
ss.public_header_files = "core-api/module1/*.h"
ss.source_files = "module2/**/*.{h,m}"
end
...
s.subspec 'moduleN' do |ss|
ss.public_header_files = "core-api/module1/*.h"
ss.source_files = "moduleN/**/*.{h,m}"
end
However, in this case the headers of the modules are only added, if I want to use the subspec. If I just want to use module1 and 2, the headers of the other modules are missing. The core-api headers folder must always be available to all modules in the framework. How do I do that?
但是,在这种情况下,仅添加模块的标题,如果我想使用 subspec。如果我只想使用 module1 和 2,则其他模块的标题都丢失了。core-api headers 文件夹必须始终可供框架中的所有模块使用。我怎么做?
回答by ERU
https://stackoverflow.com/a/33359337/4063462
https://stackoverflow.com/a/33359337/4063462
Correct podspec file should looks like this:
正确的 podspec 文件应如下所示:
s.default_subspec = 'module1'
s.subspec 'module1' do |ss|
ss.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/core-api/module1/*.h"' }
ss.source_files = "module1/**/*.{h,m}"
end
s.subspec 'module2' do |ss|
ss.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/core-api/module1/*.h"' }
ss.source_files = "module2/**/*.{h,m}"
end
...
s.subspec 'moduleN' do |ss|
ss.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/core-api/module1/*.h"' }
ss.source_files = "moduleN/**/*.{h,m}"
end
回答by teriiehina
You can define a subspec as dependency of another subspec:
您可以将子规范定义为另一个子规范的依赖项:
Pod::Spec.new do |s|
s.name = 'RestKit'
s.subspec 'Core' do |cs|
cs.dependency 'RestKit/ObjectMapping'
cs.dependency 'RestKit/Network'
cs.dependency 'RestKit/CoreData'
end
s.subspec 'ObjectMapping' do |os|
end
end
source: Podspec syntax reference
来源:Podspec 语法参考