Firebase Analytics throws errors on building in xcode - swift

I am trying to implement analytics by firebase, I have imported the FirebaseAnalytics pod in my class, but when I try to use any of it's methods, there are errors on xcode build, please help me resolve this issue, I tried most of the solutions adding the $(inherited), adding -Objc, but none of them seem to work, please point me to right solution
Implementation
import FirebaseAnalytics
class PerformanceHandler {
func recordCustomEvent(name: String, attributes: [String: Any]) {
Analytics.logEvent(name, parameters: attributes)
}
}
Error
I am on Xcode 14 and the latest version of cocoapods 1.11.3.
Podfile (Sorry wouldn't be able to add the entire podfile, here is a gist of it)
pod 'Firebase'
pod 'Firebase/RemoteConfig'
pod 'FirebasePerformance'
The PerformanceHandler class mentioned above is part of a custom pod, the code is split into respective Pods following a modular architecture.

Related

Swift Package Manager (SPM) and Cocoapod Dependency Conflict

Overview
I have two dependencies, one available as a Swift Package, and the other only available as a Cocoapod. The problem is that each has a dependency on a third package, which results in undefined behavior when multiple versions exist.
At a basic level, here is a graphic of my dependencies
APP imports:
B (SPM) imports:
C (SPM) imports:
D (SPM) <-
E (Pod) imports:
D (Pod) <-
I would like to remove the D (Pod) version and point to the D (SPM) version either via a Podfile script or build script.
More specific information:
I have a NetworkingService Swift Package that imports Firebase, and my main app imports the NetworkingService. My Podfile imports GoogleMLKit/PoseDetection. Firebase and PoseDetection share dependencies that result in undefined behavior (runtime crash) when a duplicate is present.
Note: This error should be reproducible by removing the intermediary NetworkingService package and importing Firebase to the main app as a Swift package.
Podfile
platform :ios, '15.0'
target 'MyApp' do
use_frameworks!
pod 'GoogleMLKit/PoseDetection', '2.5.0'
end
In Package.swift
.package(
name: "Firebase",
url: "https://github.com/firebase/firebase-ios-sdk.git",
.upToNextMajor(from: "8.10.0")
),
They duplicate a few dependencies, including GoogleUtilities and FBLPromises. Launching the app after pod install crashes with runtime exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FBLPromise HTTPBody]: unrecognized selector sent to instance 0x6000017685d0'
Searching that brought me to this GitHub issue where a contributor mentions:
The duplicate warnings are indicative of non-deterministic behavior. When there are multiple copies of a library, the right one may or may not be chosen.
I then attempted to refactor all Cocoapod dependencies with a modified version of this script I found linked on another StackOverflow post. The attempt was to make PoseDetection explicitly point to symbols from GoogleUtilitiesCopy and FBLPromisesCopy. But it seems that even the existence of these copies, despite pointing to the corresponding dependency, created undefined behavior.
Partial Workaround
If I run pod install followed by File > Packages > Update to latest package versions. The app will launch without an immediate runtime crash. However, I encounter other runtime crashes later within the app.***
Ideal Solution
I would like to remove the duplicate pod dependencies and point to the SPM versions either via the Podfile or a build phase script, but I'm not sure where to begin.
Firebase can be imported as a pod, but I do not want to do this because I have an existing SPM infrastructure that depends on Firebase. I'd prefer not to convert all of these packages into pods.
The main problem with SPM and Cocapods is that:
SPM is not aware of Cocapods and Cocapods not aware of SPM.
I had a similar situation where:
pod library depends on some Library networking
SPM library also depends on the same Library networking.
There are two solutions I think are worth trying.
1.) remove the pod and try to use the XCFramework version of it (should be available). that means you should manually add the library to your project and it should be selected as embed & sign and also as required.
2.) you can convert the pod library to SPM by using a simple binary target. Basically, you need to create a Package file that points to the XCFramework in its archived version (hence it should be a zip file). that way the SPM graph will handle it by itself.
I know it's not ideal, but these two approaches works for me.

XCode 12: 'SessionDelegate' has different definitions in different modules

Edit:
This problem occurs after XCode 12 Beta5. Xcode doesn't allow different modules to define same names (Probably for public classes & protocols). Alamofire and Kingfisher appears to define SessionDelegate at the same time. I'm still trying to find a solution..
I'm implementing iOS 14 Widgets in our application. I have started working with XCode 12 Beta 2 and everthing was compiling fine. When I have updated XCode to XCode 12 Beta 6, I faced with following error:
'SessionDelegate' has different definitions in different modules;
first difference is definition in module 'Kingfisher.Swift' found end
of class
I'm also attaching the screenshot of the file with error.
Is there any way to edit header files to have different names for SessionDelegate for Alamofire or Kingfisher? Is there any workaround to overcome this issue?
Here are things I have tried so far:
I have updated both Alamofire and Kingfisher to latest version
I have cleaned Podfile.lock and all pods as well as Derived Data
I tried to compile with Legacy Build System
You can try SWIFT_INSTALL_OBJC_HEADER = NO, it works for me
At this moment (Xcode 12.0 or Xcode 12.2b2), the only possible solution is to rename the Objective-C interface and avoid conflicts. This could be done by one of:
Rename conflicting class entirely, update all places where it's used (e.g. replace SessionDelegate by KingfisherSessionDelegate)
Add #objc(...) attribute to a Swift class, which will update the Obj-C interface in a generated ...-Swift.h file and avoid the names conflict.
// SessionDelegate.swift
#objc(KFSessionDelegate)
class SessionDelegate: NSObject { ... }
// Kingfisher-Swift.h
#interface KFSessionDelegate : NSObject
...
#end
This solution is already included in the Kingfisher 5.15.4 release and could be applied to any other libraries and your own frameworks.
Also, the thread on Apple forums: https://developer.apple.com/forums/thread/658012
The error is saying that you have multiple classes with the same name SessionDelegate in different modules. This error is related to Xcode 12.
For now, a quick solution is to install the module with CocoaPods (if you're using Carthage) and if needed, rename the SessionDelegate interface.
If you guys need a temporary solution, here is how for Cocoapods users:
Clone the Kingfisher library to the same folder level with your project. You can get it from Github
Open Kingfisher.xcworkspace in XCode and rename SessionDelegate.swift file under Sources/Netowking to KingFisherSessionDelegate and change the class name as well accordingly.
Rename the usages of SessionDelegate to KingfisherSessionDelegate which is only available in Sources/Networking/ImageDownloader.swift as of Kingfisher version 5.15.0
Add local path in your Podfile
pod 'Kingfisher', :path => '../Kingfisher'
I too had the same issue, sam's solution worked for me but with one change. There are 2 pods with the same definition so i changed the value of SWIFT_INSTALL_OBJC_HEADER to NO for both the pods. After doing it i was getting import error in one of the pod. So then i changed SWIFT_INSTALL_OBJC_HEADER to YES for that particular pod which was having the import error and kept the other pods SWIFT_INSTALL_OBJC_HEADER to NO. This worked for me.
for me worked when I update the 'SWIFT_INSTALL_OBJC_HEADER' key in podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == 'Alamofire'
target.build_configurations.each do |config|
config.build_settings['SWIFT_INSTALL_OBJC_HEADER'] = 'No'
end
end
end
end
end

Header 'MessageKit-Swift.h' not found

I'm trying to setup MessageKit within my app. I've been researching and trying to resolve this for a week with no luck. I'm getting an error in the module.modulemap file saying
Header 'MessageKit-Swift.h' not found
I'm deleted dervied data, ran pod update, pod install, etc.
Here is the module.modulemap code
framework module MessageKit {
umbrella header "MessageKit.h"
export *
module * { export * }
}
module MessageKit.Swift {
header "MessageKit-Swift.h"
requires objc
}
I expected MessageKit to compile within my workspace.
I tried that pod in a test project and compiles fine without issues.
I'm using Cocoapods 1.7.2 and Xcode 10.2.1, and this is my Podfile:
target 'MessageKitTest' do
use_frameworks!
pod 'MessageKit'
end
Tried to compile the MessageKitTest from the generated xcworkspace - all good on my end.
Try running a pod deintegrate then a pod install again.

Swift PaperOnboarding Module Import Error

I am sorry for such simple question, but I've searched everywhere and read through the paper-onboarding documentation but still can't find a solution to this problem.
I am building a simple iOS app project using the paper-onboarding library, by following this YT tutorial. I keep receiving the error: No such module 'PaperOnboarding'
import UIKit
import PaperOnboarding // <<<ERROR HERE>>>
class OnboardingView: PaperOnboarding {
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
}
I'm not sure how to solve this, could someone shed some light on this?
Xcode: Version 9.3
Cocoapod: Version 1.4.0
Paper-onboarding: Version 4.0.2
This error has nothing to do with the library. It's definitely an error on your part or on the configuration of your project.
How are you adding the library to your project?
If you're adding using CocaPods:
Make sure you do pod install or pod update
After that always open the .xcworkspace file in your project and not the .xcodeproj
If you are opening the correct file:
Check the POD project and the target for the pod you added and in the build settings, make sure Swift Version matches your project version.
Clean your project and run
Close and re-open XCode
but it could be several other things. But make sure all the configuration is correct.
Some Pods require you to use the use frameworks! statement in the Podfile.

Segmentation fault on fresh cocoapod install

I have a new Swift project I started on and the first thing I did was create my podfile and bring in two cocoapods.
target 'Life Stream' do
pod 'SSKeychain'
pod 'LiveSDK'
end
target 'Life StreamTests' do
pod 'SSKeychain'
pod 'LiveSDK'
end
I then ran pod setup to ensure my cocoapods were installed, then ran pod install to install my pods. The new workspace project was created and I opened Xcode in it. Everything builds.
I then added my bridge header, and started using the SSKeychain pod. Things continued to build.
Bridge:
#ifndef Lifestream_Bridging_Header_h
#define Lifestream_Bridging_Header_h
#import "AFNetworking/AFNetworking.h"
#import "SSKeyChain.h"
#import "LiveConnectClient.h"
#endif /* Lifestream_Bridging_Header_h */
class UserService {
init() {
SSKeychain.setPassword("test", forService: "service", account: "blah")
}
}
I then try to use the LiveSDK
class HttpOperation : NSOperation, LiveAuthDelegate {
let baseUl = NSURL(string: "https://api.onedrive.com/v1.0")
override func main() {
let client = LiveConnectClient(clientId: "000000004C1549C8", delegate: self)
}
func authCompleted(status: LiveConnectSessionStatus, session: LiveConnectSession!, userState: AnyObject!) {
}
}
The project built a couple of times, but now it no longer builds. I've not changed a line of code (CMD+tabbed to Safari for research). It doesn't matter if I clean the project, rebuild, or delete all of my pods and reinstall them, I can't get the project to build.
The compiler error I receive
Command failed due to signal: Segmentation fault: 11
I've seen people say this can be caused by the compiler not being able to find linked stuff. I then looked and noticed that my /frameworks folder contains all of the .a files in red (linked files?)
I assume that's because the files are missing, but why would that be? If I installed the pods via cocoapods and they were building fine, why now would those files go missing and the build stop (if that is the cause)?
I've been trouble shooting this for the last few hours and have not been able to figure it out. Any help would be appreciated.
My full compiler error log dump can be found on github
Edit
There are additional build errors associated with the unit test project, but I assume those are due to the project the unit tests depend on not building.
Use of undeclared type 'LiveAuthDelegate'
Use of undeclared type 'LiveConnectSessionStatus'
Use of undeclared type 'LiveConnectSession'
Use of unresolved identifier 'LiveConnectClient'
These errors point to the NSOperation subclass I show above. I'm not sure if that helps or not.