Install the plugin with Cordova cli:
$ cordova plugin add cordova-plugin-firebase --save
Download your Firebase configuration files, GoogleService-Info.plist for iOS and google-services.json for android, and place them in the root folder of your cordova project. Check out this firebase article for details on how to download the files.
- My Project/
platforms/
plugins/
www/
config.xml
google-services.json <--
GoogleService-Info.plist <--
...
- This plugin uses a hook (after prepare) that copies the configuration files to the right place, namely
platforms/ios/\<My Project\>/Resources
for iOS andplatforms/android
for Android. - Firebase SDK requires the configuration files to be present and valid, otherwise your app will crash on boot or Firebase features won't work.
To install the Firebase SDKs, I recommend using the CocoaPods repo. For this it is necessary to install the plugin cordova-plugin-cocoapod-support. It is not set as a dependency because it is at your discretion whether to use Pods.
$ cordova plugin add cordova-plugin-cocoapod-support --save
In your config.xml enter the dependencies. The spec attributes indicates the version of the SDK. Check the latest version available from the officials website https://cocoapods.org/pods/Firebase and https://firebase.google.com/docs/ios/setup.
<platform name="ios">
...
<preference name="pods_ios_min_version" value="7.0" /> <!-- Set the min iOS version. Default is 7.0 -->
<preference name="pods_use_frameworks" value="true" />
<pod name="Firebase/Core" version="5.18.0" />
<pod name="Firebase/Auth" version="5.18.0" />
<pod name="Firebase/Messaging" version="5.18.0" />
<pod name="Firebase/Performance" version="5.18.0" />
<pod name="Firebase/RemoteConfig" version="5.18.0" />
<pod name="Firebase/DynamicLinks" version="5.18.0" />
<pod name="Fabric" version="1.9.0" />
<pod name="Crashlytics" version="3.12.0" />
</platform>
Script's run Crashlytics:
- Open your project in Xcode, and select its project file in the Navigator.
- Select your main build target from the Select a project or target dropdown.
- Open the target's Build Phases tab.
- Click + Add a new build phase, and select New Run Script Phase.
- Add the following line to the Type a script... text box:
"${PODS_ROOT}/Fabric/run"
- Xcode 10 only: Add your app's built Info.plist location to the Build Phase's Input Files field:
$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)
Script's Crashlytics Upload Symbols (dSYM file):
Official documentation: https://firebase.google.com/docs/crashlytics/get-deobfuscated-reports?authuser=0
- Open your project in Xcode, and select its project file in the Navigator.
- Select your main build target from the Select a project or target dropdown.
- Open the target's Build Phases tab.
- Click + Add a new build phase, and select New Run Script Phase.
- Add the following line to the Type a script... text box:
"${PODS_ROOT}/Fabric/upload-symbols" -gsp "${PROJECT_DIR}/<TARGET_NAME>/Resources/GoogleService-Info.plist" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
Note: replace <TARGET_NAME> with the name of target.
- Download the framework SDK zip (this is a ~500MB file and may take some time).
- Unzip and see the README file for which Frameworks to include in to your project. The list of SDK:
- FirebaseCore.framework
- FirebaseAuth.framework
- FirebaseMessaging.framework
- FirebasePerformance.framework
- FirebaseRemoteConfig.framework
- FirebaseDynamicLinks.framework
- Add the ObjC linker flag in your Other Linker Settings in your target's build settings.
- Fabric & Crashlytics SDK https://fabric.io/kits/ios/crashlytics/manual-install
"${PROJECT_DIR}/Fabric.framework/run"
If you want to update or change version of frameworks it is possible to add customized tags inside the config.xml. A hook set the new versions after the prepare. These settings are not mandatory because they are by default in the plugin. This stratagem helps us to update the addiction libraries without waiting for a new release of the plugin.
<platform name="android">
...
<dependency-classpath name="com.android.tools.build:gradle:3.3.0" />
<dependency-classpath name="com.google.gms:google-services:4.2.0" />
<dependency-classpath name="io.fabric.tools:gradle:1.26.1" />
<framework-implementation name="com.google.firebase:firebase-core:16.0.7" />
<framework-implementation name="com.google.firebase:firebase-auth:16.1.0" />
<framework-implementation name="com.google.firebase:firebase-messaging:17.3.4" />
<framework-implementation name="com.google.firebase:firebase-config:16.1.3" />
<framework-implementation name="com.google.firebase:firebase-perf:16.2.3" />
<framework-implementation name="com.google.firebase:firebase-dynamic-links:16.1.5" />
<framework-implementation name="com.google.android.gms:play-services-tagmanager:16.0.7" />
<framework-implementation name="com.crashlytics.sdk.android:crashlytics:2.9.8" />
...
</platform>