我遇到了一个名为DCIntrospect-ARC的pod问题,它只能在DEBUG模式下运行。它会在运行之前检查是否定义了DEBUG宏。但是,它没有在CocoaPods目标中定义,即使我在Xcode中以调试模式运行它也无法运行,因为未定义DEBUG宏。
我可以使用
在podspec中定义DEBUG宏s.xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) DEBUG=1' }
但是这为所有构建配置定义了DEBUG,而不仅仅是DEBUG配置。
答案 0 :(得分:21)
您可以在Podfile中使用post_install挂钩。
此挂钩允许您在生成的Xcode项目写入磁盘之前对其进行任何上次更改,或者您可能要执行的任何其他任务。 http://guides.cocoapods.org/syntax/podfile.html#post_install
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.name != 'Release'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'DEBUG=1']
end
end
end
end
答案 1 :(得分:11)
感谢John,我完成了自定义Podfile脚本,该脚本还将优化级别更改为零并启用断言。
我有多个调试配置(用于ACC和PROD),所以我需要更新几个属性以进行调试。
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
if config.name.include?("Debug")
# Set optimization level for project
config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
# Add DEBUG to custom configurations containing 'Debug'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
if !config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].include? 'DEBUG=1'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'DEBUG=1'
end
end
end
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.name.include?("Debug")
# Set optimization level for target
config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
# Add DEBUG to custom configurations containing 'Debug'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
if !config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].include? 'DEBUG=1'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'DEBUG=1'
end
# Enable assertions for target
config.build_settings['ENABLE_NS_ASSERTIONS'] = 'YES'
config.build_settings['OTHER_CFLAGS'] ||= ['$(inherited)']
if config.build_settings['OTHER_CFLAGS'].include? '-DNS_BLOCK_ASSERTIONS=1'
config.build_settings['OTHER_CFLAGS'].delete('-DNS_BLOCK_ASSERTIONS=1')
end
end
end
end
end
答案 2 :(得分:1)
截至目前,已接受的答案对Swift Pods无效。 以下是对该答案的单行更改,似乎对两者都有效。
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.name != 'Release'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'DEBUG=1']
config.build_settings['OTHER_SWIFT_FLAGS'] = ['$(inherited)', '-DDEBUG']
end
end
end
end
答案 3 :(得分:1)
我认为接受的答案不适合我。 config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'DEBUG=1']
||=
用于指定空或nil变量,但如果config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
不为空?
根本无法修改数组。我的值为["POD_CONFIGURATION_PRODUCTION=1", "$(inherited)"]
。
所以我给了完整的anwser。
post_install do |installer_representation|
installer_representation.pods_project.build_configurations.each do |config|
if config.name == 'Release' || config.name == 'Production' || config.name == 'Release-InHouse'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= []
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] |= ['$(inherited)', 'NDEBUG=1']
end
end
end
|| = []确保变量是有效数组。并且arrayA |= arrayB
表示arrayA + arrayB并删除重复的元素,然后返回到arrayA。
答案 4 :(得分:-2)