-force_load on cocoapods libraries - cocoapods

How can a podfile control the -force_load flag for the libraries it manages? I have a situation where a third-party library is using headers that arent available and one of the given solutions is to remove the -ObjC linker flag, but this is needed and inserted by cocoapods.
The other solution is to use the -force_load flag on each library. How is this added to cocoapods' podfile so that it is applied to each library?

You can do this in your Podfile using a post_install hook. It will look something like this:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings["OTHER_LDFLAGS"] = '$(inherited) "-force_load"'
end
end
end

Related

can I run pod lib lint for a framework not on simulator arch

I have a podspec framework that has a subspec that has a arm64 arch support only , but when trying to pod lib lint, it returns error because pod lib lint lint for simulator.
How can I make run pod lib lint only for arm64 and pass ?

Xcode 12 cocoapods indirect framework dependency missing?

After update to Xcode 12 project would no longer build.
undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_DDLog", referenced from:
objc-class-ref in Bouncer.o
ld: symbol(s) not found for architecture x86_64
DDLog is defined in CocoaLumberjack. which is a dependency of FrameworkA which is a dependency of FrameworkB (the Test Project)
Podspec extract FrameworkA:
Pod::Spec.new do |s|
[...]
s.default_subspec = 'Core'
s.subspec 'Core' do |co|
co.source_files = 'FrameworkA_Objc_DependencyIssue/Classes/**/*'
co.dependency 'CocoaLumberjack', '~> 3.1'
end
end
Podspec extract FrameworkB:
Pod::Spec.new do |s|
[...]
s.source_files = 'FrameworkB_Objc_DependencyIssue/Classes/**/*'
s.dependency 'FrameworkA_Objc_DependencyIssue/Core', '~> 0.1.2'
# s.dependency 'CocoaLumberjack' # Adding direkt dependency fixes problem!
end
This setup does compile with Xcode 11.
It seems that it was a "bug" that this would compile in Xcode 11. Adding the dependency to FrameworkB solves the issue (see comment in podspec extract FramworkB of updated question)
First Way: To do that, navigate to Build Settings of your project and add Any iOS Simulator SDK with value arm64 inside Excluded Architecture
or
If you are using custom XCConfig files, you can simply add this line for excluding simulator architecture.
EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64
Second Way :
You can manually add the Excluded Architecture in your Pod project's Build Settings, but it will be overwritten when you use pod install.
In place of this, you can add this snippet to your Podfile. It will write the necessary Build Settings every time you run pod install
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings[‘EXCLUDED_ARCHS[sdk=iphonesimulator*]’] = ‘arm64’
end
end
Please try and let me know if it helps

Unable to build Xcode project: "XCTest' does not contain bitcode"

I have generated a basic react-native project and have configured the ios project to use Cocoa Pods.
The project builds fine and works with the iOS simulator when I run react-native run-ios, but if I open the project in Xcode and try to build and run on a physical device, I get the following:
ld: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/XCTest' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/XCTest' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am using version Xcode version 10.2.1, react-native 0.59.8.
I'm new to Xcode and any ideas on how I could resolve this would be very very welcome!
Additional Info
I don't know much about Xcode configuration but I tried out disabling bitcode in the Podfile.
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
After a pod install, clean and build this resulted in another build failure with the linker complaining that it couldn't find certain files. Removing it from the podfile+clean+build resulted in the original error again.

SDWebImage causes a "not a prototype" warning

I'm working on an IOS app and I'm using SDWebImage (v 3.8.2 installed with Cocoa Pods). When I compile I get a warning that reads:
This block declaration is not a prototype
This error refers to the line
typedef void(^SDWebImageNoParamsBlock)();
in the SDWebImageCompat.h file.
Is there a way to fix this? I tried updating the pod but this seems to be the latest version.
I'm using XCode 9.0.
inhibit_all_warnings! doesn't work for me. I add a pch file to the project, and add #pragma resolved warnings. Hope it can help you.
// Suppress warnings of framework
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wstrict-prototypes"
#import <TheWarningPods/File.h>
#import TheWarningPods;
#pragma clang diagnostic pop
Add inhibit_warnings => true to your Podfile:
pod 'SDWebImage', :inhibit_warnings => true
Basically this will silence all warnings for the specified pod.
Alternatively, you can add inhibit_all_warnings! to the top of your Podfile to silence all warnings for all pods.

CocoaPods podspec with per architecture flags

QUICK VERSION: I have a library of code that I'm creating a Cocoapods spec file for. It needs different compiler flags based on the architecture. Is that possible?
Explanatory background:
One of the library's files contains some ARM NEON intrinsics code. For armv7 & armv7s the flags are:
s.compiler_flags = '-mfloat-abi=softfp', '-mfpu=neon', '-mcpu=cortex-a9'
The last flag causes a (totally reasonable) compile error on arm64.
Xcode supports per-architecture flags in the Build Settings area, so this has been building fine, until now when a podspec wrapper is required.
Is there a way to configure a CocoaPods spec with per-architecture flags?
One solution, I found via Can you set architecture specific Build Settings in an .xcconfig file in Xcode 4.3?, use xcconfig:
# Common flags
s.compiler_flags = '-mfloat-abi=softfp', '-mfpu=neon'
# Per-arch flags
s.xcconfig = { 'OTHER_CFLAGS[arch=armv7]' => '$(inherited) -mcpu=cortex-a9' ,
'OTHER_CFLAGS[arch=armv7s]' => '$(inherited) -mcpu=cortex-a9'}
Minor CocoaPods bug here, the $(inherited) flag double up the parameters in the Pods.xcconfig:
OTHER_CFLAGS[arch=armv7] = $(inherited) -mcpu=cortex-a9 $(inherited) -mcpu=cortex-a9
OTHER_CFLAGS[arch=armv7s] = $(inherited) -mcpu=cortex-a9 $(inherited) -mcpu=cortex-a9
I wonder if there's a more spec-friendly way to do this via the actual compiler-flags flag?

Resources