Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Handle Google Play Services Conflicts In NativeScript Mobile Applications

TwitterFacebookRedditLinkedInHacker News

I’ve been developing with NativeScript for a few years now, but only recently have I started working with the various services offered by Google Play. Using a single Google Play service such as Google Analytics works great, but as soon as you start adding more, you’ll start noticing Android conflicts during the build process.

Different plugins have different requirements on the underlying library versions. For example, one plugin might expect version 9, while another version 10, creating a versioning conflict.

We’re going to see how to get around these common problems that expand beyond NativeScript and into other development frameworks such as Apache Cordova and Ionic Framework.

Let me share a story about how I ran into this problem. I was helping someone with push notifications and background geolocation in a NativeScript application. At build time, we were getting an Android specific error complaining about the plus (+) symbol in our Gradle file.

What went wrong:
A problem occurred evaluating root project 'Sample'.
> Failed to apply plugin [id 'com.google.gms.google-services']
   > For input string: "+"

This was not exactly straight-forward in terms of the issue.

Turns out the background geolocation plugin was using the following:

compile 'com.google.android.gms:play-services-location:+'

The push notification plugin was also using Google Play, in this case Firebase Cloud Messaging (FCM):

compile 'com.google.firebase:firebase-messaging:10.0.1'

Now, it isn’t obvious that the push notification plugin was using Google Play which is the source of our error, but it is in fact using 10.0.1 of the library, while the geolocation plugin was using a wildcard.

So how do you fix the problem now that we’ve confirmed where the disconnect is?

The first thing you can do is contact the developer of the plugin that is using the wildcard. I tried to contact the developer of the background geolocation plugin, but was spoken down to and was essentially told to drop dead. My GitHub comments were since removed by the developer.

If contacting the developer doesn’t work, you have two more options. You can try to match the versions yourself and hope that the plugin code uses that particular version of the library. In this instance, we want to replace the wildcard plus (+) symbol with 10.0.1 to match that of the other plugin. The other option would be to not use that plugin.

Conclusion

Conflicts between NativeScript plugins are very common when building Android applications. The conflicts are a result of two plugins trying to use the same library, but of different versions in the Gradle files. The simplest approach to resolving these conflicts is to edit either of the plugins to make the Gradle files match.

More information on solving Google Play conflicts in Gradle files can be found in this other great follow-up post, unrelated to NativeScript.

In case you’re curious, I would never recommend anyone using the NativeScript background geolocation plugin created by Chris Scott of TransistorSoft. For a paid plugin, the developer offers terrible support by giving rude and aggressive responses to questions asked by customers. Save your money and time for better things as Apple won’t approve the plugin in iTunes.

Nic Raboy

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in C#, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Unity. Nic writes about his development experiences related to making web and mobile development easier to understand.