2014-02-12 49 views
8

查看Cocoapods的項目文件Pods.xcodeproj它看起來像每個庫的每個方案(Debug方案除外)的優化級別爲Fastest, Smallest方案的Cocoapods優化級別

有沒有簡單快捷的方法來改變Podfile或其他一些Cocoapods的配置,這樣當我使用pod install時,針對特定方案的優化級別是None

enter image description here

回答

12

我使用Podfile post_install掛鉤。喜歡這個。

post_install do |installer| 
    installer.project.build_configurations.each do |config| 
    if config.name.include?("Debug") 
     config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0' 
    end 
    end 
end 
+0

如果這個工程......你是我的英雄... –

+0

當初如果config.name包括' .include?(「Localhost」)。 –

+0

拯救生命!謝謝! –

3

如果你也想在DEBUG宏添加與斷言調試啓用,您可以使用下面的腳本:

post_install do |installer| 
    installer.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.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 
12

任何人0.38.0或更高版本見狀使用的CocoaPods:

使用「pods_project」而不是「project」

以前的答案使用單詞「project」(installer.project.build_configurations.each)

項目已棄用,並替換爲pods_project。 https://github.com/CocoaPods/CocoaPods/issues/3747

post_install do |installer| 
    installer.pods_project.build_configurations.each do |config| 
    if config.name.include?("Debug") 
     config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0' 
    end 
    end 
end 
0

相反的post_install您可以添加以下行Podfile:

project 'ProjectName', 'DebugConfigurationName' => :debug