Cocoapods: turning MagicalRecord logging off - ios

Turning MagicalRecord logging off requires a #define to be made before it is first included in the project, but in the case of a project managed by Cocoapods I have no access to add a #define in the Pods project. How do I turn logging off completely in this scenario?
Took me a few hours to figure out a way to do it, posting here in the hope it will help others.
EDIT: this is not a duplicate as it discusses turning logging off under Cocoapods

You can use a post_install hook to modify pretty much any build setting. Just add this code to your 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
Note that this will only disable logging in the debug configuration - logging is disabled by default in the release configuration.

In my case, I was building a library that depended on MagicalRecord. I didn't want my users to have to add a post_install in their Podfile to silence the noisy logging, so I added it to my podspec instead.
s.prefix_header_contents = '#define MR_ENABLE_ACTIVE_RECORD_LOGGING 0'
This automatically adds this #define statement to Pods-prefix.pch, which silences MagicalRecord logging in projects that use my pod.

I updated ank's answer for those using the new cocoapods version alongside MagicalRecord 2.3.0:
post_install do |installer|
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;
s.push('MR_LOGGING_DISABLED=1') if config.to_s == "Debug";
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end
end
Changes:
project renamed to pods_project
Target Pods-MagicalRecord renamed to MagicalRecord
Macro MR_ENABLE_ACTIVE_RECORD_LOGGING renamed to MR_LOGGING_DISABLED and value changed from 0 to 1

You can switch off logging in Pod project!
Simply add Preprocessor Macros:
Just go into "Pods" (!!!) project.
Then find out Pods-MagicalRecord target.
Choose "Build Settings" tab
Find "Apple LLVM 6.1 Preprocessing" -> "Processor Macros"
Rollout "Processor Macros" and add to "Debug" schema: "MR_ENABLE_ACTIVE_RECORD_LOGGING=0"
It`s all!

For the development branch (version 2.3.0 and higher) of Magical Record logging seems to still not work correctly. When imported like this:
pod 'MagicalRecord', :git => 'https://github.com/magicalpanda/MagicalRecord', :branch => 'develop'
I have no logging output on my Xcode console. But I altered the post_install script of the Cocoapod. The following should enable logging:
https://gist.github.com/Blackjacx/e5f3d62d611ce435775e
With that buildsetting included in GCC_PREPROCESSOR_DEFINITIONS logging of Magical Record can be controlled in 2.3.0++ by using [MagicalRecord setLoggingLevel:]

Related

Double-quoted include [all Facebook SDK imports], expected angle-bracketed instead

I am getting the following warning in iOS Xcode builds:
Double-quoted include "FBSDKDeviceLoginCodeInfo.h" in framework header, expected angle-bracketed instead.
This is apparently a new default warning in Xcode 12 which will throw a warning anywhere you #import or #include with "quotes.h" instead of <brackets.h>.
I am getting this for all of the Facebook SDK imports. There are a few StackOverflow proposed solutions out there, but none of them works.
These solutions do not work:
go in the project's Build Settings a just set the option Quoted Include In Framework Header to No :
you can use Cocoapods version 1.10.0.rc.1 temporarily until 1.10.1 is officially available -> gem install cocoapods -v '1.10.0.rc.1'
Another option is to update your Podfile (add below code) to disable the warning flag CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER setting for all pods in your project
post_install do |installer|
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER'] = 'NO'
end
end
end
end
You can disable these warnings for your entire project by navigating to your project's "build settings", finding the field "other linker flags" and adding the following flag: -Wno-quoted-include-in-framework-header
Worked for me:
rm -rf ~/Library/Developer/Xcode/DerivedData/
rm -rf ~/Library/Caches/CocoaPods/
pod deintegrate
pod update
These solutions were written 7 or 8 months ago and DO NOT WORK FOR ME.
Are there any new solutions beyond manually editing hundreds of occurrences of this?

Cocoapods header conflict between libopus and abseil

I have an Xcode project with the following Podfile :
pod '!ProtoCompiler-gRPCPlugin', '~> 1.33'
pod 'gRPC', '~> 1.33'
pod 'libopus'
The issue is that since GRPC decide to use Abseil as a dependency, a weird conflict is happening.
When compiling, I get the following error on Pods/abseil/base/config.h:
'absl/base/options.h' file not found
but the previous call in the stack is actually located in Pods/libopus/float/warped_autocorrelation_FLP.c :
#include "config.h"
This doesn't make sense as the specific config.h libopus is trying to get is actually in the same pod directory.
Any idea how to fix this? I tried multiple versions of libopus, but the static version is causing issues of its own.
It appears the conflict was caused by the HEADER_MAP = YES build setting "leaking" headers without proper namespacing.
The fix for this was to isolate libraries with header conflicts and then :
Setting their HEADER_MAP to NO
Add headers through HEADER_SEARCH_PATHS
To automate it in your Podfile :
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# Prevent header conflicts
if ['LIBRARY_A', 'LIBRARY_B'].include? target.name
config.build_settings["USE_HEADERMAP"] = "NO"
config.build_settings["HEADER_SEARCH_PATHS"] = "${PODS_TARGET_SRCROOT}/**"
end
end
end
end

Custom Compiler Flags for GoogleSignIn/Crashlytics/Firebase

I'm trying to resolve compiler flags, like -Wno-auto-import, in my main project. But I can't set the compiler flags for GoogleSignIn/Crashlytics/Firebase pods. I tried to add this following code to my Podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['WARNING_CFLAGS'] = "$(inherited) -Wno-auto-import"
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
end
end
end
But I'm still getting auto import compiler errors. It's working fine for facebook signin and all other pods. The compiler flags are also listed under Pods -> GTMOAuth2 -> Apple LLVM 9.0 - Custom Compiler Flags -> Other Warning Flags -> -Wno-auto-import
How do I fix this?
You are able to silence all cocoapod warnings by specifying this flag in your pod file:
inhibit_all_warnings!
You can be a bit more granular and specify it per pod if you wanted:
pod 'GoogleSignIn', inhibit_warnings: true
pod 'Crashlytics', inhibit_warnings: true
pod 'Firebase', inhibit_warnings: true
This may not work if you have -Weverything enabled in your project, which is generally discouraged because it includes warnings that are buggy or still in development. This flag will give you false-positives for your cocoapod frameworks. More information here: https://softwareengineering.stackexchange.com/questions/122608/clang-warning-flags-for-objective-c-development/124574#124574
If you still wish to try manually edit the warning flags - then your code sample looks fine, make sure it's not getting overwritten by an xcconfig file
Also make sure you do a clean so that no warnings are left over from previous builds! Xcode can be a pain and keep them around longer than they need to be sometimes. Check the actual build log produced to validate if they are still being raised

TesseractOCRiOS | Warning: Multiple build commands for output file

versions:
TesseractOCRiOS 4.0.0
CocoaPods 1.2.1
When i'm building on simulator - everything is fine, but when i'm trying to build on my iPhone xCode gives me next warning:
Warning: Multiple build commands for output file /Users/Username/Library/Developer/Xcode/DerivedData/ProjectName-hjheurpncvhpfbabezufoumrybad/Build/Products/Debug-iphoneos/TesseractOCRiOS/TesseractOCR.framework/PrivateHeaders/config_auto.h
Faced with the same problem recently, definitely not the best, but acceptable workaround - just delete one of the duplicate lines "config_auto.h" with path "./Pods/TesseractOCRiOS/TesseractOCR/include/leptonica/" in "Build Phases"-"Headers"-"Private" settings of TesseractOCRiOS target.
OCR recognition functionality does not affected by this change.
See screenshot for details.
If you're using cocoapods, you can add following script at the end of your pod file:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'TesseractOCRiOS'
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
header_phase = target.build_phases().select do |phase|
phase.is_a? Xcodeproj::Project::PBXHeadersBuildPhase
end.first
duplicated_header_files = header_phase.files.select do |file|
file.display_name == 'config_auto.h'
end
duplicated_header_files.each do |file|
header_phase.remove_build_file file
end
end
end
end
Just noticed that it's also disabling bitcode. Remove it if that's not what you need. The script removes the duplicate header files since they are under private section only.
I think you have a problem in your project directory. You have a duplicate file of config_auto.h
Go to your Target , Delete config_auto.h under the build phases.
Hope!! This helps you

How to use OTHER_SWIFT_FLAGS in a Pod

Has anybody tried to use build configuration flags in a Swift based Pod? I am trying to use a post_install hook to add "OTHER_SWIFT_FLAGS" to a private Swift pod that I'm working on. Basically, I want to be able to do something like #if DEV #elseif QA #else #endif to change endpoints based on the target that I'm using. The project I'm integrating the pod with also uses DEV & QA flags which work fine with corresponding DEV & QA targets.
Here is a post_install hook that I came up using help from other similar posts:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'Pods-Test-QA'
puts "Found #{target.name}. Adding Swift Flag..."
target.build_configurations.each do |config|
puts "Configuration: #{config}"
config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)']
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DQA'
puts "#{config.build_settings['OTHER_SWIFT_FLAGS'].inspect}"
end
end
if target.name == 'Pods-Test-DEV'
puts "Found #{target.name}. Adding Swift Flag..."
target.build_configurations.each do |config|
puts "Configuration: #{config}"
config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)']
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DDEV'
puts "#{config.build_settings['OTHER_SWIFT_FLAGS'].inspect}"
end
end
end
end
After running pod install the post_install successfully adds the flags as shown in the image below for Pods-Test-QA & Pods-Test-DEV.
However, when I run the project using QA or DEV targets and use the following flags it always hits PROD:
#if DEV
print("DEV ENVIRONMENT")
#elseif QA
print("QA ENVIRONMENT")
#else
print("PROD ENVIRONMENT")
#endif
Is there something I'm missing?
Also, for some reason Pods-Test-QA.debug.xcconfig & DEV don't seem to be updated with the flags I've added. Does anyone have any idea why it's not updating in the .xcconfig files?
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
Any help would be appreciated. Thanks in advance.
Using:
cocoapods (1.0.1)
Xcode 7.3.1
If you develop your own pod and would like to add some flags depending on the configuration you can do so by mentioning it in your podspec file.
My goal was to add 'BETA' flag to my pod if parent's project active configuration contains 'BETA' in its name without post-install hooks.
s.pod_target_xcconfig = {
'OTHER_SWIFT_FLAGS[config=*Beta*]' => '-DBETA',
}
Podspec not only allows to do add custom flags but gives an opportunity to use wildcards.
The result: if my parent project uses 'Extra Early Beta' configuration then the following fork in pod's sources goes to 'BETA'
#if BETA
// Beta related code
#else
// Code I don't need in beta.
#endif

Resources