Pregunta

Tengo problemas con un pod llamado DCIntrospect-ARC que solo debería funcionar en modo DEBUG.Comprueba si la macro DEBUG está definida antes de ejecutarla.Sin embargo, no está definido en el destino de CocoaPods y, aunque estoy ejecutando en modo de depuración en Xcode, no se ejecuta porque la macro DEBUG no está definida.

Puedo definir la macro DEBUG en podspec usando

s.xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) DEBUG=1' }

pero esto definió DEBUG para todas las configuraciones de compilación y no solo la configuración DEBUG.

  1. ¿Es esto un problema de CocoaPods?¿No debería definirse generalmente la macro DEBUG para Pods?
  2. ¿Puedo solucionar esto en el archivo Podspec y declarar la macro DEBUG solo en la configuración de compilación de depuración?
¿Fue útil?

Solución

Puede usar el gancho posterstall en podfile.

Este gancho le permite realizar cualquier último cambio en el proyecto Xcode generado antes de que esté escrito en el disco, o cualquier otra tarea que desee realizar. 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

Otros consejos

Gracias a John, completé mi script de podfile personalizado, que también cambia el nivel de optimización a cero y permite las afirmaciones.

Tengo múltiples configuraciones de depuración (para ACC y PROD), por lo que necesitaba actualizar varias propiedades con fines de depuración.

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

La respuesta aceptada a partir de ahora no funciona para las vainas SWIFT. Aquí hay un cambio de una línea a esa respuesta que parece funcionar para ambos.

    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

Creo que la respuesta aceptada no es tan adecuada para mí. config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'DEBUG=1']

||= se utiliza para asignar una variable vacía o nula, pero si la config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] no está vacío ?

La matriz no se puede modificar en absoluto.El valor es ["POD_CONFIGURATION_PRODUCTION=1", "$(inherited)"] para mí.

Entonces di la respuesta completa.

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 

||= [] asegúrese de que la variable sea una matriz válida.y arrayA |= arrayB significa matrizA + matrizB y elimina el elemento repetido y luego regresa a la matrizA.

Aún más fácil:solo asegúrate de tener el DEBUG=1 macro a su GCC_PREPROCESSOR_DEFINITIONS en su proyecto en xCode para el modo de depuración pero no para el modo de lanzamiento.Si lo agrega al nivel del proyecto (no a objetivos específicos), será heredado por todos los objetivos (prueba de depuración, objetivos personalizados, etc.).Esto está configurado de forma predeterminada en proyectos nuevos y, en general, se espera que esté allí.Si se lo pierde, eso podría tener un gran impacto.

Si aún no funciona, asegúrese de tener también $(inherited) en todos sus objetivos para GCC_PREPROCESSOR_DEFINITIONS.CocoaPods y DEBUG cuentan con eso.

settings

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top