Duplicate symbols when integrating Firebase and Google Sign In SDKs manually without Cocoapods

This is how I solved it although it is far from the ideal solution.

(This solution can be applied to any case where two static libraries cause "duplicate symbol" error due to both libraries containing common classes and using -ObjC or -all_load flag.)

Copy the GoogleSignInDependencies file inside the GoogleSignInDependencies.framework in a separate location PATH. This file is a fat file meaning it has codes for different architectures.

Open the terminal and go to PATH.

$ cd PATH

Run the command following command to get info about the fat library.

$ lipo -info GoogleSignInDependencies

You will get the following result.

Architectures in the fat file: GoogleSignInDependencies are: armv7 i386 x86_64 arm64

As you can see there are 4 architectures in the fat file.

Get the thin files (file that contains code for only one architecture) from the fat file by running the following commands.

$ lipo -thin armv7 GoogleSignInDependencies -output armv7.a
$ lipo -thin i386 GoogleSignInDependencies -output i386.a
$ lipo -thin x86_64 GoogleSignInDependencies -output x86_64.a
$ lipo -thin arm64 GoogleSignInDependencies -output arm64.a

You will get 4 thin files named armv7.a, i386.a, x86_64.a and arm64.a.

Delete the GoogleSignInDependencies file, we don't need it anymore.

Create 4 new folders named armv7, i386, x86_64 and arm64. Then move the thin files armv7.a, i386.a, x86_64.a and arm64.a to the respective folders. You should have a folder structure like the following.

arm64
    arm64.a
armv7
    armv7.a
i386
    i386.a
x86_64
    x86_64.a

Go to each of the 4 folders from terminal and extract the object files (*.o) from the thin files using the following commands.

$ cd armv7
$ ar -x armv7.a
$ cd ../i386
$ ar -x i386.a
$ cd ../x86_64
$ ar -x x86_64.a
$ cd ../arm64
$ ar -x arm64.a

After running these commands each of the 4 folders should contain the following files. (This can change in future versions.)

__.SYMDEF
GTMGeometryUtils_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMLogger_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMNSDictionary+URLArguments_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMNSString+URLArguments_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMOAuth2Authentication_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMOAuth2SignIn_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMOAuth2ViewControllerTouch_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMSessionFetcher_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMSessionFetcherLogging_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMSessionFetcherService_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMSessionUploadFetcher_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMSynchronizationAsserts_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o

Delete the files that are conflicting with the Firebase library from each of the 4 folders. You need to delete these 6 files. (This can change in future versions.)

GTMLogger_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMNSDictionary+URLArguments_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMSessionFetcher_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMSessionFetcherLogging_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMSessionFetcherService_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o
GTMSessionUploadFetcher_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.o

Delete the thin files armv7.a, i386.a, x86_64.a and arm64.a.

Combine the remaining object files into thin files by running the following commands.

$ cd armv7
$ libtool -static *.o -o armv7-new.a
$ cd ../i386
$ libtool -static *.o -o i386-new.a
$ cd ../x86_64
$ libtool -static *.o -o x86_64-new.a
$ cd ../arm64
$ libtool -static *.o -o arm64-new.a

Copy the newly created thin files armv7-new.a, i386-new.a, x86_64-new.a and arm64-new.a to a new location PATH_NEW. You can delete everything else inside PATH.

Combine the new thin files into a new fat file by running the following commands.

$ cd PATH_NEW
$ lipo -create armv7-new.a i386-new.a x86_64-new.a arm64-new.a -output GoogleSignInDependencies-new

Use the newly generated GoogleSignInDependencies-new in place of GoogleSignInDependencies in your Xcode project.

I strongly recommend the following article for deeper understanding of the things.

http://atnan.com/blog/2012/01/12/avoiding-duplicate-symbol-errors-during-linking-by-removing-classes-from-static-libraries


Update 2019-01-17 - Hacking Google SignIn is now redundant!

As per xmasalov's reply below, Firebase has been updated to include all the dependencies needed for Google SignIn in the /Invites directory. Just add:

  • GoogleSignIn.framework
  • GTMOAuth2.framework
  • GoogleToolboxForMac.framework

from that directory to you project. you no longer need to download the GoogleSignIn frameworks from Google at all.

My original reply (please ignore):

If you have this problem, I've just written a bash shell script which does all the work for me. I've saved it as a Gist. use it at your own risk.

Please read all the comments above as the script may need tweaking to match changes in newer versions of the frameworks.


Updated answer

As of 2018-12, Google Sign-In for iOS team removed dependency on the GTM OAuth 2 library.

Google Sign-In iOS SDK Release Notes

2018-11-29 -- v4.4.0 Removed dependency on the GTM OAuth 2 library.



Original answer

As of 2018-11, one can find all that is needed for GoogleSignIn to work with FirebaseAnalytics and FirebaseAuth in Firebase/Invites folder:

  • GoogleSignIn.framework
  • GTMOAuth2.framework

No need to add GoogleSignInDependencies.framework, works like a charm.