1
votes

I am reading articles and testing ways to implement analytics and push notifications in my Ionic app using firebase.

My ionic app targets both android and ios platforms, so where do I place the google-services.json firebase file? Do I have to create an 2 apps within firebase if I need to use firebase for android and iOS?

I am reading many articles some of which say root folder, whereas some mention to put it in the apps folder. Some say we have to then update the config.xml to include the foll:

<resource-file src="google-services.json" target="app\google-services.json" />

I have also read that we need to update the gradle file with application and project level dependencies.

I have put the file in platform/android/app folder and things are working correctly now.

I just want to know what is the best practice when using Ionic and Firebase, where do I place the file and what config changes do I have to make?:

  1. For an Ionic android app
  2. For Ionic iOS app
  3. For Ionic app for both android and iOS platforms
1

1 Answers

0
votes

Have a look at the documentation of the firebase plugin : https://github.com/arnesson/cordova-plugin-firebase

For Android, you have the google-services.json file, and for iOS you have the GoogleService-Info.plist file. These files are required by firebase to work on both iOS and Android. You have to place theses files at the same level as config.xml.

This plugin uses a hook (after prepare) that copies the configuration files to the right place, namely platforms/ios/\/Resources for ios and platforms/android for android.

So you don't need the resource-file directive in your config.xml, since it is copied automatically.

You don't need to edit the build.gradle file, but If you have other google play plugins installed (like maps or admob), the compilation may not work.

Your build may fail if you are installing multiple plugins that use Google Play Services. This is caused by the plugins installing different versions of the Google Play Services library. This can be resolved by installing cordova-android-play-services-gradle-release.

If your build is still failing, you can try installing cordova-android-firebase-gradle-release. For more info, read the following comment about locking down the specific versions for play services and firebase. It is suggested to use + instead of 15.+ to ensure the correct versions are used.

EDIT : Since you're using cordova-plugin-firebase-analytics and not cordova-plugin-firebase, it seems that they didn't implement any hook to copy the files. You'll have to place these directives in your config.xml :

<platform name="android">
  <resource-file src="google-services.json" target="app\google-services.json" />
  ...
<platform name="ios">
  <resource-file src="GoogleService-Info.plist" />
  ...

Be sure to install cordova-support-google-services