【问题标题】:Firebase Cloud Messaging FCM build error Cannot add task ':processDebugGoogleServices' as a task with that name already existsFirebase Cloud Messaging FCM 构建错误无法添加任务“:processDebugGoogleServices”作为具有该名称的任务已存在
【发布时间】:2018-08-18 16:20:30
【问题描述】:

我正在尝试将推送通知与 Firebase 云消息传递和 Cordova FCM 一起使用。我的 google-services.jsonconfig.xml 位于根文件夹中,而 platforms/android/ 文件夹中的相同文件。使用 ionic cordova build 我得到了错误:

配置根项目“android”时出现问题。

无法添加任务“:processDebugGoogleServices”,因为具有该名称的任务已存在。

我已经安装了:

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

之前还有一个原因:

cordova 插件添加 cordova-plugin-googleplus ...

现在我得到了什么:

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

编辑自:

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 也被编辑为 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
}

不知道哪里出了问题,建议会有所帮助

【问题讨论】:

    标签: android cordova firebase ionic-framework gradle


    【解决方案1】:

    问题是您在 Gradle 配置中指定的 GoogleServices 插件版本存在冲突:

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

    com.google.gms:google-services:3.0.0
    

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

    com.google.gms:google-services:3.2.0
    

    您需要解决此问题,以便版本匹配。

    【讨论】:

    • 您好,我对classpath 'com.google.gms:google-services:3.0.0'3.2.0' 都进行了尝试,也对上面列出的所有目录进行了相同的尝试:3.0.0 和 3.2.0,但在所有情况下我都遇到了相同的错误
    • 尝试删除 cordova-support-google-services 因为它是多余的。此外,您还需要删除/重新添加 Android 平台以应用更改
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-02
    • 2016-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    相关资源
    最近更新 更多