TL;DR: To prevent build failures caused by including different versions of Play Services library components.
Some Cordova plugins include the Play Services library to faciliate them.
Most commonly, these are now included into the Cordova project by specifying them as Gradle dependencies (see the Cordova plugin spec documenation).
The problem arises when these plugins specify different versions of the Play Services library components. This can cause build failures to occur, which are not easy to resolve without changes by the plugin authors to align the specified versions. See these issues:
To resolve these version collisions, this plugin injects a Gradle configuration file into the native Android platform project, which overrides any versions specified by other plugins, and forces them to the version specified in its Gradle file.
If you're encountering similar problems with the Android Support and/or Firebase libraries, checkout the sister plugins:
This is because the versions of the Play Services and Firebase libraries are related - see Android Library Versions for details.
You can use cordova-android-firebase-gradle-release to override the Firebase SDK component versions to align with the Play Services library component versions specified via this plugin in order to resolve build issues.
Other plugins that reference the Google Services plugin
There are certain Cordova plugins which reference the Google Services plugin in their Gradle config, for example:
The Google Services plugin itself references a particular version of the Play Services library
The version of Play Services library referenced depends on the version of the Google Services plugin referenced by the Cordova plugin.
If a plugin (such as cordova-plugin-fcm) is included into a Cordova project along with this plugin, then this plugin is unable to override the Play Services library version specified by the Google Services plugin.
Attempting to do this will result in a build failure with an error message such as Found com.google.android.gms:play-services-location:12.+, but version 9.0.0 is needed for the google-services plugin.
The only solution you can implement using this plugin is to specify the same version as required by the Google Services plugin
In the example error above, that would mean installing this plugin with: cordova plugin add cordova-android-play-services-gradle-release --variable play-services-location=9.0.0
Requirements
This plugin requires cordova@8+ (CLI) and cordova-android@7+ (Android platform).
Since the plugin uses hook scripts it will not work in Cloud Build environments such as Phonegap Build.
By default, this plugin pins a recent version of each of the Play Services library components.
You can see what the currently pinned versions are by looking at the <preference>'s in the plugin.xml.
Other versions
You may want to specify a version of the Play Services library components - see here for a list recent versions.
Library component versions are specified in the Android build as Gradle artifacts in the format packageId:componentId:versionNumber, for example com.google.android.gms:play-services-location:17.0.0.
To override the default version when installing this plugin, specify a plugin variable where the variable key is the component ID and the value is the version number.
For example, if you want to install v17.0.0 of the Play Services library Location component, you'd specify the version via the variable:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
请发表评论