FCMPlugin build failed due to version conflict with google gms services

I use this with ionic 2 for windows for android. When I add the cordova-plugin-fcm plugin, I can no longer build the project. Here is the error I get:

BUILD FAILED                                                                                     

Total time: 4.697 secs                                                                           

Error: cmd: Command failed with exit code 1 Error output:                                        
FAILURE: Build failed with an exception.                                                         

* What went wrong:                                                                               
Execution failed for task ':processDebugGoogleServices'.                                         
> Please fix the version conflict either by updating the version of the google-services plugin (i
nformation about the latest version is available at https://bintray.com/android/android-tools/com
.google.gms.google-services/) or updating the version of com.google.android.gms to 9.2.0.        

* Try:                                                                                           
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get mor
e log output.                                                                                    

The following is a snippet of my config.xml file:

 <plugin name="cordova-plugin-console" spec="~1.0.3"/>
  <plugin name="cordova-plugin-facebook4" spec="~1.7.3">
    <variable name="APP_ID" value="XXX"/>
    <variable name="APP_NAME" value="XXX"/>
  </plugin>
  <plugin name="cordova-plugin-whitelist" spec="~1.2.2"/>
  <plugin name="cordova-plugin-statusbar" spec="~2.1.3"/>
  <plugin name="cordova-plugin-splashscreen" spec="~3.2.2"/>
  <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
  <plugin name="cordova-plugin-camera"/>
  <plugin name="cordova-plugin-geolocation" spec="https://github.com/apache/cordova-plugin-geolocation"/>
  <plugin name="cordova-plugin-googlemaps" spec="https://github.com/phonegap-googlemaps-plugin/cordova-plugin-googlemaps">
    <variable name="API_KEY_FOR_ANDROID" value="XXXX"/>
    <variable name="API_KEY_FOR_IOS" value="XXXX"/>
  </plugin>
  <plugin name="cordova-plugin-file-transfer" spec="~1.5.1"/>
  <plugin name="cordova-plugin-file" spec="~4.2.0"/>
  <plugin name="cordova-plugin-device" spec="~1.1.2"/>

I read this and related ones that suggest adding this line to build.gradle (which is created automatically using ionic):

apply plugin: 'com.google.gms.google-services'

I tried adding it to build-extras.gradle with no luck.

In my build.graddle, I see this line:

// PLUGIN GRADLE EXTENSIONS START
apply from: "cordova-plugin-fcm/upfront-FCMPlugin.gradle"
// PLUGIN GRADLE EXTENSIONS END

And also these lines:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    debugCompile project(path: "CordovaLib", configuration: "debug")
    releaseCompile project(path: "CordovaLib", configuration: "release")
    compile "com.facebook.android:facebook-android-sdk:4.14.+"
    compile "com.google.android.gms:play-services-maps:+"
    compile "com.google.android.gms:play-services-location:+"
    // SUB-PROJECT DEPENDENCIES END
}

What am I missing and how can I fix this problem?

+4
source share
6

.

plugings:

https://github.com/mauron85/cordova-plugin-background-geolocation

https://github.com/fechanique/cordova-plugin-fcm

1). : .

2). : /cordova-plugin-fcm/src/android/FCMPlugin.gradle

:

apply plugin: com.google.gms.googleservices.GoogleServicesPlugin

:

ext.postBuildExtras = {
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}

3) : .

4) : /Android/Project.properties

"+" "11.4.2":

com.google.firebase:firebase-core:+
com.google.firebase:firebase-messaging:+
com.google.android.gms:play-services-location:+

:

com.google.firebase:firebase-core:11.4.2
com.google.firebase:firebase-messaging:11.4.2
com.google.android.gms:play-services-location:11.4.2

:).

+6

- , google-maps, , , .

0

, Project → platform.. > android → . gradlefile

buildscript {
repositories {
        jcenter()
        mavenLocal()
    }
dependencies {
    classpath 'com.android.tools.build:gradle:+'
    classpath 'com.google.gms:google-services:3.0.0' //change this line
}

} // : 'com.google.gms.google-services' //class id (string), root gradle : com.google.gms.googleservices.GoogleServicesPlugin

0

, , , , , Android . cordova-plugin-fcm cordova-plugin-googleplus.

/Android/build.gradle

dependencies {
   classpath 'com.android.tools.build:gradle:2.2.3'
   // I added this:
   classpath 'com.google.gms:google-services:3.1.0'
}

..

allprojects {
  repositories {
   // changed the + to 10.2.0 
   compile "com.google.android.gms:play-services-auth:10.2.0"
   compile "com.google.android.gms:play-services-identity:10.2.0"
  }
}

// at end of the promptForReleaseKeyPassword function, add this:

def promptForReleaseKeyPassword() {
  ...
  apply plugin: 'com.google.gms.google-services'
}

android/project.properties( + 10.2.0)

cordova.system.library.3=com.google.android.gms:play-services-auth:10.2.0
cordova.system.library.4=com.google.android.gms:play-services-identity:10.2.0

cordova-plugin-fcm/mobile-FCMPlugin.gradle( )

dependencies {
  classpath 'com.android.tools.build:gradle:+'
  classpath 'com.google.gms:google-services:3.1.0'
}

...

// apply plugin: 'com.google.gms.google-services' moved into this postBuildExtras function.
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
ext.postBuildExtras = {
      apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}
0

1

 ionic cordova platform remove android
 ionic cordova platform add android

2

ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated

npm install @ionic-native/fcm

then delete them

ionic cordova plugin remove cordova-plugin-fcm-with-dependecy-updated

npm uninstall @ionic-native/fcm

Step 3 Now Add the Plugin

ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated

Now use it in your component.ts as

declare var FCMPlugin:any; 

at the top of the component

and then use it in a function like

FCMPlugin.getToken(function(token){

            console.log(token);

        },(error)=>{

            console.log(error);

        });

maybe it will help others

0
source

Source: https://habr.com/ru/post/1656589/


All Articles