尝试使用 CocoaPods 0.38 关闭 MagicalRecord 登录时出错
Error when trying to turn MagicalRecord loggin off with CocoaPods 0.38
我正在使用来自这个 SO 问题的 ank 解决方案:Cocoapods: turning MagicalRecord logging off 在我将 CocoaPods 更新到最新版本 (0.38.2) 之前它曾经运行良好。现在每当我 运行 pod install
命令它 returns 几个错误。
供参考,这是 ank (link) 分享的原始 Podfile 片段:
post_install do |installer|
target = installer.project.targets.find{|t| t.to_s == "Pods-MagicalRecord"}
target.build_configurations.each do |config|
s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
s = [ '$(inherited)' ] if s == nil;
s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug";
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end
end
我遇到的第一个问题是Podfile中的project
需要替换成pods_project
,所以我就这么做了。
但让我卡住的是它无法识别 build_configurations
语句,正如您在下面的控制台错误中看到的那样:
...
Generating Pods project
[!] An error occurred while processing the post-install hook of the Podfile.
undefined method `build_configurations' for nil:NilClass
...
我用谷歌搜索了这个问题,但无论是从 SO 还是 gitHub 或其他网站都找不到有效的解决方案。我相信可能需要进行更多更改才能使该代码段在此版本的 CocoaPods 上再次运行,所以我想知道是否有人提出了解决此问题的方法,或者是否有另一种方法可以关闭登录MagicalRecord(顺便说一句,我使用的是 2.2 版)。
这是我的 Podfile 的最后一部分:
post_install do |installer|
target = installer.pods_project.targets.find{|t| t.to_s == "Pods-MagicalRecord"}
target.build_configurations.each do |config|
s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
s = [ '$(inherited)' ] if s == nil;
s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug";
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end
end
任何帮助将不胜感激:)
我发现您需要使用 "MagicalRecord"
而不是 "Pods-MagicalRecord"
,方法是在 post_install 中添加以下行:
puts installer.pods_project.targets
我的工作解决方案代码:
# Turn off Magical Record logging in debug mode - in release mode it is off by default
target = installer.pods_project.targets.find{|t| t.to_s == "MagicalRecord"}
target.build_configurations.each do |config|
s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
s = [ '$(inherited)' ] if s == nil;
# Uncomment one matching your version
#s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug"; # MagicalRecord < 2.3
#s.push('MR_LOGGING_DISABLED=1') if config.to_s == "Debug"; # MagicalRecord 2.3+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end
我正在使用来自这个 SO 问题的 ank 解决方案:Cocoapods: turning MagicalRecord logging off 在我将 CocoaPods 更新到最新版本 (0.38.2) 之前它曾经运行良好。现在每当我 运行 pod install
命令它 returns 几个错误。
供参考,这是 ank (link) 分享的原始 Podfile 片段:
post_install do |installer|
target = installer.project.targets.find{|t| t.to_s == "Pods-MagicalRecord"}
target.build_configurations.each do |config|
s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
s = [ '$(inherited)' ] if s == nil;
s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug";
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end
end
我遇到的第一个问题是Podfile中的project
需要替换成pods_project
,所以我就这么做了。
但让我卡住的是它无法识别 build_configurations
语句,正如您在下面的控制台错误中看到的那样:
...
Generating Pods project
[!] An error occurred while processing the post-install hook of the Podfile.
undefined method `build_configurations' for nil:NilClass
...
我用谷歌搜索了这个问题,但无论是从 SO 还是 gitHub 或其他网站都找不到有效的解决方案。我相信可能需要进行更多更改才能使该代码段在此版本的 CocoaPods 上再次运行,所以我想知道是否有人提出了解决此问题的方法,或者是否有另一种方法可以关闭登录MagicalRecord(顺便说一句,我使用的是 2.2 版)。
这是我的 Podfile 的最后一部分:
post_install do |installer|
target = installer.pods_project.targets.find{|t| t.to_s == "Pods-MagicalRecord"}
target.build_configurations.each do |config|
s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
s = [ '$(inherited)' ] if s == nil;
s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug";
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end
end
任何帮助将不胜感激:)
我发现您需要使用 "MagicalRecord"
而不是 "Pods-MagicalRecord"
,方法是在 post_install 中添加以下行:
puts installer.pods_project.targets
我的工作解决方案代码:
# Turn off Magical Record logging in debug mode - in release mode it is off by default
target = installer.pods_project.targets.find{|t| t.to_s == "MagicalRecord"}
target.build_configurations.each do |config|
s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
s = [ '$(inherited)' ] if s == nil;
# Uncomment one matching your version
#s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug"; # MagicalRecord < 2.3
#s.push('MR_LOGGING_DISABLED=1') if config.to_s == "Debug"; # MagicalRecord 2.3+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end