Push Notifications with Firebase Cloud Messaging and Cordova build FCM error Cannot add task ':processDebugGoogleServices' as a task with that name already exists


#1

Hello, I’m trying to use Push Notifications with Firebase Cloud Messaging and Cordova FCM. My google-services.json located in root folder with config.xml and same file in platforms/android/ folder. With ionic cordova build I got error:

A problem occurred configuring root project ‘android’.

Cannot add task ‘:processDebugGoogleServices’ as a task with that name already exists.

I’ve installs:

cordova plugin add cordova-support-google-services --save
ionic cordova plugin add cordova-plugin-fcm
npm install --save @ionic-native/fcm

and previously by another reason:

cordova plugin add cordova-plugin-googleplus …

Now what I got:

platforms/android/cordova-plugin-fcm/myapp-FCMPlugin.gradle:

buildscript {
	repositories {
            jcenter()
			mavenLocal()
        }
    dependencies {
        classpath 'com.android.tools.build:gradle:+'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}
// 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

platforms/android/cordova-support-google-services/myapp-build.gradle:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }

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

// 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
ext.postBuildExtras = {
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}

platforms/android/project.properties:

 
target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.google.android.gms:play-services-auth:11.0.1
cordova.system.library.2=com.google.android.gms:play-services-identity:11.0.1
cordova.system.library.3=com.facebook.android:facebook-android-sdk:4.14.+
cordova.system.library.4=com.google.firebase:firebase-core:+
cordova.system.library.5=com.google.firebase:firebase-messaging:11.0.1
cordova.gradle.include.1=cordova-plugin-fcm/myapp-FCMPlugin.gradle
cordova.gradle.include.2=cordova-support-google-services/myapp-build.gradle

which is edited from:

target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.google.android.gms:play-services-auth:+
cordova.system.library.2=com.google.android.gms:play-services-identity:+
cordova.system.library.3=com.facebook.android:facebook-android-sdk:4.14.+
cordova.system.library.4=com.google.firebase:firebase-core:+
cordova.system.library.5=com.google.firebase:firebase-messaging:+
cordova.gradle.include.1=cordova-plugin-fcm/myapp-FCMPlugin.gradle

platforms/android/build.gradle which is also edited as project.properties:

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.google.android.gms:play-services-auth:11.0.1"
    compile "com.google.android.gms:play-services-identity:11.0.1"
    compile "com.facebook.android:facebook-android-sdk:4.14.+"
    compile "com.google.firebase:firebase-core:+"
    compile "com.google.firebase:firebase-messaging:11.0.1"
    // SUB-PROJECT DEPENDENCIES END
}

plugins/cordova-plugin-fcm/scr/android/FCMPlugin.gradle:

buildscript {
    repositories {
            jcenter()
            mavenLocal()
        }
    dependencies {
        classpath 'com.android.tools.build:gradle:+'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}
// 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

plugins/cordova-support-google-services/build.gradle:


buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }

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

// 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
ext.postBuildExtras = {
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}

Not sure what is wrong, advice would be helpful


#2

Not the solution but I recently had conflict using different version of FCM, that leads me to the following question:

If you redo your edit of platforms/android/project.properties and use explicitly a FCM version (like 11.0.1 or 11.6.2) instead of +, does that help?

Sorry that’s really the only things which popped up in my mind, the rest might be above my knowledges but I hope this could helps a bit


#3

Hello,

I’ve tried both 11.0.1 and 11.6.2 instead of +, and also for directories /plugins/cordova-plugin-fcm/scr/android/FCMPlugin.gradle and plugins/cordova-support-google-services/build.gradle classpath 'com.google.gms:google-services:3.0.0' and 3.2.0' same version separately, and also same for all listed directories labove, but in all cases I got same error


#4

Hi Lado,

Did you ever resolve this error?