Ionic v4 - push plugin build issues with Android

I have a working Ionic v4 app. I can build and run it on both device types (Android, iPhone) as well as in my browser.

Now I am trying to add PUSH capability but every push plugin I add causes an Android build error.

There are a few different errors, but generally they seem related to the following:

  • gradle build issue
  • duplicate GoogleServices plugin
  • issue with “+” instead of specific version in the properties file
  • etc.

I have tried various “solutions” and “hacks”, some of which get me past one build error only to encounter another. At one point I had a build but the screen wouldn’t display.

I have tried removing and re-adding the plugin as well as the platform but to no avail. I have also noticed that sometimes if I remove the plugin I can no longer build what was working before. All of this without making a single line of change to my code.

I have all the latest Ionic/Cordova stuff by running the command “npm update -g ionic cordova”. And I have tried the following plugins:

  • phonegap-plugin-push
  • cordova-plugin-fcm-with-dependecy-updated
  • cordova-plugin-firebase
  • cordova-plugin-fcm

This is killing me. Any help would be appreciated!
(Any help that has a long-term effect whereby there’s no hacking involved or things that get lost when you remove the platform would be doubly appreciated!)

This seems promising but didn’t work for me:

Using the link I mentioned earlier I experimented with various settings and finally got a successful Android build.

For me it was this that did the trick:

cordova plugin add cordova-android-play-services-gradle-release --variable PLAY_SERVICES_VERSION=16+

The version number at the end was critical for success in my situation. Otherwise my Android build failed if I tried a different value or left out the version parameter completely.

If you run into this issue try adding this plugin, and figure out which version number works for you. All it really seems to be doing is putting that version information into the config.xml file, something like this:

  <plugin name="cordova-android-play-services-gradle-release" spec="^2.1.0">
      <variable name="PLAY_SERVICES_VERSION" value="16+" />

This may work with other plugins, but I just happened to have a successful build with cordova-plugin-firebase