Using firebase framework within cocoa touch framework - swift

I’m developing a framework where I need to use firebase internally.
I added firebase framework manually to my framework as cocoapods didn’t work.
Now, I’m able to build my framework and use it on my local system as expected. But it creates problem when I ship it to other devs and it fails with following errors.
I tried several ways like adding firebase.h in framework's header file. But none of the approaches are working.
Also, apart from this approach, I tried manually adding firebase to main app, where it gave the logs saying duplicate frameworks found.
What am I doing wrong in adding firebase to framework ?
I've already checked some of the related question such as This and this

I suspect, that after transferring the code into the other machine, owner does not runs
pod install
terminal command, so physically the framework does not exist.

I can confirm Aaron answer: be sure to specify a complete, correct path.
I usually avoid as the "evil" cocoaPods (getting worse and worse to use..)
so I downloaded the zip and added all the folder.
I specify ONLY "Framework search path" and "Header search path".
Library search path is empty.
note: as suggested by documentation, I added FireBase.h AND module.modulemap, TOO. (and set -objC flag, too)

Adding one or more search paths for the framework and header file will resolve the issue.

First de integrate pod after try with fresh.
pod 'Firebase'
pod 'Firebase/Storage'
pod 'Firebase/Core'
pod 'Firebase/Database'
pod 'Firebase/Auth'
pod 'Firebase/Messaging'

CocoaPods 1.5.0 static library feature does not work with FirebaseAnalytics because of the non-modular headers in FirebaseAnalytics.h.
Reported at CocoaPods/CocoaPods#7542.
Workaround is a similar post_install step similar to this.
Because the fix is a breaking change, it is targeted for the next Firebase major release.

Related

Linker command failed with exit code 1 after installing CocoaPods and firebase pod

I'm trying to use the firebase pod, however getting this (see image) error message when a run is attempted.
I followed this guide to install Cocoapods and added the firebase dependency to the Podfile.
p.s I tried to clean it a bunch of times.
I got stuck for awhile trying to solve this, but the solution turned out to be very easy :)
If you are using Cocoapods in your project, one needs to use xcworkspace to build instead of xcproject.
If you are using Cocoapods and build from  xcproject , it will ignore the Cocoapods libraries you need.
Sometimes its because of you might be declaring an object with same variable name.
Clear the repeating variable name change it. After that clean your project and build again.
Its worked for me....! Thanks.
I faced the same problem for hours and solved it with a simple hack. Just do clean and then Build
This error will also trigger when several components (files) with identical names were added to Xcode workspace.
Renaming them will fix this error.
A bit late, but what did the trick for me were cmd + q xcode, navigate to project folder, pod update, reopen open the .xcworkspace file, clean project and run/build again.
Sometimes occurs when you perform an invalid delete through cocoapods.
In my case I installed a framework through cocoapods which required bitcode set to "enabled", later when I longer needed it removed it from Podfile and pod install.
That's when encountered this error, solving it by setting the required targets to "disabled" in bitcode option.
I've got the same error when I was trying to configure cellIdentifiers in different Controllers.
I declared two variables globally with the same name. To solve this error I just renamed the second variable.
#import "ResultsTableViewController.h"
NSString *const kNormalCellidentifierName = #"NormalStoryCelll";
#interface ResultsTableViewController ()
#end
For me it was because the pod that I was using used Swift and I didn't include the use_frameworks! line in my podfile.
I didn't include that line before and therefore had to create a Swift file in my project and a Objective-C bridging header (which Apple offers to do for you the first time you add a swift file to your project).
If you told it not to create the bridge, then you can use this guys tutorial to manually create it as well as the settings needed.
I have tried a lot to fix this issue and failed for every attempt.
Then i just simply used:
pod install
and to my surprise, simply it solved my issue.

pods in a framework, import that framework for main project in swift

The idea is to have an api framework (new project -> cocoa touch framework) for example "SuperApi". SuperApi use pods like Alamofire, ObjectMapper and whatever I need.
Next I want to integrate that SuperApi into my app like a normal framework.
I tried different ways. I tried to add it at "Embedded Binaries" and/or tried to add superApi at "Linked Frameworks and Libraries". Without success. I always linked the whole framework-folder.
import SuperApi threw always an error: could not find framework
Then I read something about workspaces where I can have a lot of projects parallel. This seems really overpowered for an api.
Create a framework without pods (xcodeproj) is no problem. There are a lot of descriptions in web. But what is a (good) solution for my problem?
I don't want to write my own http-networking + JSON parser. Thanks for input.
Why don't you add your SuperApi as a pod of your main project? You can have it either as a local pod, directly linking the last commit or using your own private repo
There's a very nice tutorial by Ray Wenderlich: https://www.raywenderlich.com/99386/create-cocoapod-swift
Thanks Eli. I found this video, it's more up to date
https://www.youtube.com/watch?v=gNMNeqXKnzw&t=964s (thanks to you Mr. Levi Bostian - you made my day)
Unfortunately this video is a litte bit outdated too.
You run into a Swift 2/3 issue. So you have to create a .swift-version in your git. For example Alamofire did it like this: https://github.com/Alamofire/Alamofire/blob/master/.swift-version
You can do it like this in your pod-folder: echo 3.0 > .swift-version
I ran into a second issue, because my pod wasn't up to date. So update your pod sudo gem install cocoapods --pre
Last but not least I had a warning in my podspec, so I have to use pod spec lint --allow warnings
Better way is to fix the warning ;)

Cocoapods: Cannot load module 'Alamofire' as 'Alamofire'

Update: I solved the question. Please see my answer below (underneath the question and comments).
This question was marked as a duplicate, but it's different because it is a brand new error that I couldn't find through any searches.
I tried installing Alamofire into my XCode project.
As per their their tutorial, I installed cocoapods onto my system.
I then navigated to the folder of my existing xcode project in the terminal, and did:
pod init
I then edited the new pod file and added:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target 'RainyShinyCloudy' do
pod 'Alamofire', '~> 4.4'
end
Finally, I executed the command:
pod install
My terminal told me the install was successful.
But when I opened the .xcworkspace, made a new swift class and tried to import Alamofire, I got this error:
One possible reason could be that I had tried to install an earlier version of alamofire earlier, deleted it and then installed this.
But I really don't know how that could have mattered.
Thanks for any help you guys can give me.
Actually it failed because you were trying to import AlamoFire and not Alamofire. Imports are case sensitive.
Update: I posted an answer earlier that was wrong.
But now I actually figured it out.
I made a new project, went to the settings menu by clicking on the name of my app in the project explorer.
Then I went to Linked frameworks and libraries which is at the very bottom of the General tab.
I pressed that little + icon, selected Alamofire.framework. and set the status to required
Following this, cleaning and rebuilding the project made the error go away.

Using installed pod in swift project

I'm trying to create a swift program that uses sockets. In order to do that, I'm trying to use the SwiftSocket library by installing it using CocoaPods.
My Podfile is basic:
target 'socket' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for socket
pod 'SwiftSocket'
end
According to the installation guide of SwiftSocket, after installing the pod I should be able to use the TCPClient right away.
Still, I fail to use the class in my main.swift file as it doesn't find the class.
I've searched the web to see what I'm missing here, but all I found are guides on how to bridge Pods written in ObjectiveC but not on pods written in Swift.
Any help?
Thanks
EDIT: With jamshes reginahit suggestion, I've added SwiftSocket.framework to the Linked Frameworks and Libraries, in addition to the Pods_socket framework that was already present.
Now the build is successful, but I gut a runtime error of Thread1: signal SIGABRT with the payload:
yld: Library not loaded: #rpath/SwiftSocket.framework/Versions/A/SwiftSocket
Referenced from: /Users/jonathan/Library/Developer/Xcode/DerivedData/socket-buglawjxihebcabvcihcbdrtkcxt/Build/Products/Debug/socket
Reason: image not found
(lldb)
EDIT2: Something was funky with my Xcode. I've reinstalled it and now it seems to work fine. Thanks to everybody for the help. :)
I would like to comment, but I don't have enough reputation.
Anyway did you write something like:
import SwiftSocket
in the class where you need it? Also, did you open the project with the xcworkspace extension?
If nothing works try to clean and rebuild the project
Based on my checking of the SwiftSocket Library, it seems that what you did should be fine (it should be pod 'SwiftSocket' referring to "Installation" section), I assume that you missed to add :
import SwiftSocket
in your main.swift class.
And yes, they are not mentioning that in "Code examples" section because they -probably- assume that importing it in your .swift file should be obvious.
Once CocoaPods is finished installing, you need to start using the .xcworkspace instead of your .xcproject file. So close your project, open the workspace (same directory), and import SwiftSocket.
Your Podfile seems correct, after that, you need to launch a terminal from your project directory:
cd ~/Desktop/MyProject/
Then run: pod install command.
This will create a .xcworkspace file and a Pods directory.
Now you have to open the .xcworkspace file with Xcode.
Donc forget to import yout pod like this: import SwiftSocket
Also take a look at the CocoaPods documentation: https://guides.cocoapods.org/using/using-cocoapods.html

Sharing realm between containing app and extension

I am sharing the realm between containing app and extension (custom Keyboard), and it works ok on simulator, but when I'm trying to run this app on the real device I have the following error:
Cannot load underlying module for 'RealmSwift'
It's kinda strange that it is not an issue with simulator but ok. Let's add pods.framework to Link Binary With Libraries for my extension.
.../Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h:19:1:
Duplicate interface definition for class
'BFCancellationTokenRegistration'
OK. Let's remove it.
Cannot load underlying module for 'RealmSwift'
Can't argue that. Let's try to add RealmSwift.framework to the extension.
.../Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h:19:1:
Duplicate interface definition for class
'BFCancellationTokenRegistration'
OK. After several iterations there are several Pods.framework in my project folder and RealmSwift.framework too. Let's remove them all except one Pods.framework. Let's change target membership for this framework to the app and the extension.
.../Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h:19:1:
Duplicate interface definition for class
'BFCancellationTokenRegistration'
and
Cannot load underlying module for 'RealmSwift'
together.
How could this be fixed?
Update: I am using Realm and Parse cocoapods.
It should just be a matter of creating a second section in your Podfile to let you specify the dependencies for your app extension as well as your main app.
target 'MyApp' do
pod 'RealmSwift'
end
target 'MyAppExtension' do
pod 'RealmSwift'
end
CocoaPods does a lot of extra steps in setting up the dependencies and installing them into your target at compile time, so I don't think simply copying Pods.framework to the extensions build steps will work.
If you've got multiple references to the same files floating around, then it may be a good idea to completely delete every CocoaPods-related file/folder from your project, and running pod install again to make sure it's all set up again properly.
Let me know how you go!