FCMPlugin build fail due to version conflict with

2019-02-10 19:40发布

I'm using this with ionic 2 on Windows for Android. When I add cordova-plugin-fcm plugin, I cannot build the project anymore. Here is the error that I'm getting:

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.                                                                                    

Below is a snippet of my config.xml:

 <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 have read this and this related posts which suggest adding this line to build.gradle (which is created automatically by ionic):

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

I have 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 issue?

5条回答
老娘就宠你
2楼-- · 2019-02-10 20:08

I had the same issue. It turned out I had phonegap-plugin-push and cordova-plugin-fcm installed. They were causing the conflict. I had to remove one of them. Credits to: https://github.com/fechanique/cordova-plugin-fcm/issues/90#issuecomment-243435681

查看更多
对你真心纯属浪费
3楼-- · 2019-02-10 20:08

To resolve this error, go to the Project-->platform..>android-->.gradlefile and Modify the line

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

} // apply plugin: 'com.google.gms.google-services' // class must be used instead of id(string) to be able to apply plugin from non-root gradle file apply plugin: com.google.gms.googleservices.GoogleServicesPlugin

查看更多
Anthone
4楼-- · 2019-02-10 20:09

Something wierd happened for me, when i remove the google-maps plugin, build the project and run it on my device, everything worked perfectly and all the maps loaded just fine.

查看更多
该账号已被封号
5楼-- · 2019-02-10 20:10

I came across this thread, in case this is helpful to anyone, here are the set of files and changes I made so that my android client would build fine. I was having a conflict with cordova-plugin-fcm and cordova-plugin-googleplus. Here is a

platforms/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 (Changed + to 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 (this file was a tricky one)

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
}
查看更多
干净又极端
6楼-- · 2019-02-10 20:13

I solved it.

plugings:

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

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

1). remove platform: cordova platform rm android.

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

replace:

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

with:

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

3) add platform: cordova platform add android.

4) modify: platforms/android/project.properties

change the "+" for "11.4.2":

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

should look like this:

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

that's all :).

查看更多
登录 后发表回答