没有为CocoaPods目标定义DEBUG预处理器宏

Mik*_*søe 19 xcode objective-c ios cocoapods

我遇到了一个名为DCIntrospect-ARC的pod问题,它只能在DEBUG模式下工作.它会在运行之前检查是否定义了DEBUG宏.但是,它没有在CocoaPods目标中定义,即使我在Xcode中以调试模式运行,它也无法运行,因为未定义DEBUG宏.

我可以使用podspec定义DEBUG宏

s.xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) DEBUG=1' }
Run Code Online (Sandbox Code Playgroud)

但是这为所有构建配置定义了DEBUG,而不仅仅是DEBUG配置.

  1. 这是一个CocoaPods问题吗?通常不应该为Pods定义DEBUG宏吗?
  2. 我可以在Podspec文件中解决这个问题,并仅在Debug构建配置中声明DEBUG宏吗?

joh*_*ope 22

您可以在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
Run Code Online (Sandbox Code Playgroud)

  • 使用cocoapods版本1.0.0.beta.3我必须使用installer_representation.pods_project而不是installer_representation.project (3认同)

Ant*_*ine 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
Run Code Online (Sandbox Code Playgroud)