Integrating Firebase into Ionic + CocoPods Google Toolbox workaround
Since the Mobile SDK for Google Analytics is officially deprecated, Google is now recommending Firebase Analytics. When creating your Mobile Application using Ionic, Firebase is fairly easy to integrate using the native Firebase Plugin. However, there are a few workarounds needed to get the project to build correctly.
Create Firebase Account and App Profile at: https://console.firebase.google.com
Download the config files and save to your project root folder. GoogleService-Info.plist for iOS. google-services.json for Android.
- Install plugin to project
$ ionic cordova plugin add cordova-plugin-firebase $ npm install @ionic-native/firebase --save
- Add reference to config.xml file (if not element not present)
<platform name="ios"> <resource-file src="GoogleService-Info.plist" />
iOS Build Errors
You may encounter the error “ld: library not found for -lGoogleToolboxForMac” when building the project. This is caused by the CocoaPod dependencies and Ionic.
- Open a terminal to the platform/ios directory and run the following
$ pod install
- When opening the project in XCode, use the
.xcworkspacefile instead of
To streamline this process, create the following bash files to run before and after a platform is added (source: Ionic KB Article)
Create the scripts
#!/bin/bash pod repo update
#!/bin/bash pod install --project-directory='./platforms/ios/'
Reference the scripts in config.xml
<platform name="ios"> <hook src="update_pods.sh" type="before_platform_add" /> <hook src="run_pods.sh" type="after_platform_add" /> ...
Add execute permissions to your scripts
$ chmod +x update_pods.sh $ chmod +x run_pods.sh
Photo by Krivec Ales from Pexels