Firebase and Google Sign - patching Google's code

iOS   Google   Firebase  

I have a project I've been messing around with for a while and recently I decided to re-write it in Swift. As part of doing this I took a look at the technologies I had employed for the server, asking myself 'Should I persist with these technologies?'

The short answer was - No.

I'd previously gone with a roll-your-own approach to my server. Using Node.js, MySQL, Knex and Bluebird promises. All good products and if I ever feel the need to do more javascript, I'll be reaching for them. But this time I really wanted to get someone else to do most of the heavy lifting. So I hummed and hah'd around for a while, read lots of blogs and eventually decided to try out Google Firebase, mainly because it was free (always important with toy projects) and appeared to have all sorts of functionality I figured I could use. So I included the Firebase database SDK into my iOS client project following Google's instructions.

This worked fine until I attempted to create some data which crashed and burned because Firebase Databases have security enabled by default. Some reading later and I worked out I needed to add in authentication. Some more reading after that and I figured out Firebase Database can use a wide range of authentication systems, one of which was Google's single sign in solution. AKA Your google Id. This seemed perfect as I've used my Google Id for authentication in the past and it should integrate seamlessly with Firebase Database.

Wrong!

Despite what Google's integration documentation says, combining Firebase Database and Google Sign In in the same project caused the compiler to throw a teeny tiny tantrum, spitting out numerous duplicate symbol errors. The culprits being a number of classes duplicated in both the Firebase and Google Sign In SDKs.

I thought 'No, this can't be right. I must have done a boo boo somewhere' and hit the inter webs again. But after a lot more reading I concluded I'd actually done it right for once, and it was Google who had stuffed up as supported by this StackOverFlow question which also gave me a solution. Basically it said:

  1. Copy the GoogleSignInDependencies.framework to a tmp directory.
  2. Extract the binaries for the various architectures.
  3. Extract the individually compiled class binaries.
  4. Remove the duplicate class binaries which clash with the Firebase binaries.
  5. Combine the left over binaries back into a new framework.
  6. Include this new framework in your project.

Honestly I had doubts that was the best solution. I mean - hacking Googles binaries? WTF!

So I shot a question at Google who (to their credit) emailed me back the next day. They pointed me at the same StackOverFlow question I'd found and suggested that was the best answer they could offer.

Seriously?

They were telling me to patch their own product so it would work the way their instructions said it should in the first place! - Gotta admit, I was a bit gob smacked.

So long story short, I went and followed the StackOverFlow answer, tearing GoogleSingInDependencies apart and re-assembling it. So far, it's worked. I'm no longer getting compilation problems and everything appears to be working, although I've not used much of Firebase's functionality as yet.

So the summary of this waffle is this:

  1. I'm still surprised a company can put out two products like Firebase and Google Sign In, and recommend to use them together when they know you can't without some relatively advanced skills.
  2. I wrote a script to do all the dirty work of fixing the framework. It works for me, hopefully it will help someone else.

Comments powered by Disqus