在添加和配置"cordova-plugin-firebase"后,在应用程序(cordova build android)中执行构建时出错. [英] Error executing the build in the app (cordova build android), after adding and configuring "cordova-plugin-firebase"

查看:279
本文介绍了在添加和配置"cordova-plugin-firebase"后,在应用程序(cordova build android)中执行构建时出错.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Cordova创建了一个应用,然后按照说明准备与Firebase插件集成的应用:

  1. 创建了密钥库(需要与Firebase集成).
  2. 我在Firebase中创建了应用程序的项目,并通知了哈希 存储在密钥库中.
  3. 我安装了插件"cordova-plugin-firebase".
  4. 将文件google-services.json复制到 项目.
  1. Created the keystore (needed to integrate with Firebase).
  2. I created the project of the app in Firebase and I informed the hash stored in the keystore.
  3. I installed the plugin "cordova-plugin-firebase".
  4. Copy the file google-services.json to the root folder of the project.

在阅读了插件和Firebase文档之后,我遇到了此错误:

:app:processDebugGoogleServices失败

:app:processDebugGoogleServices FAILED

失败:构建失败,并出现异常.

FAILURE: Build failed with an exception.

*出了什么问题: 任务':app:processDebugGoogleServices'的执行失败. >文件google-services.json丢失.没有它,Google Services插件将无法运行. 搜索位置: /myAppCordova2/platforms/android/app/src/nullnull/debug/google-services.json /myAppCordova2/platforms/android/app/src/debug/nullnull/google-services.json /myAppCordova2/platforms/android/app/src/nullnull/google-services.json /myAppCordova2/platforms/android/app/src/debug/google-services.json /myAppCordova2/platforms/android/app/src/nullnullDebug/google-services.json /myAppCordova2/platforms/android/app/google-services.json

* What went wrong: Execution failed for task ':app:processDebugGoogleServices'. > File google-services.json is missing. The Google Services Plugin cannot > function without it. Searched Location: /myAppCordova2/platforms/android/app/src/nullnull/debug/google-services.json /myAppCordova2/platforms/android/app/src/debug/nullnull/google-services.json /myAppCordova2/platforms/android/app/src/nullnull/google-services.json /myAppCordova2/platforms/android/app/src/debug/google-services.json /myAppCordova2/platforms/android/app/src/nullnullDebug/google-services.json /myAppCordova2/platforms/android/app/google-services.json

SO中建议的解决方案: 将google-services.json复制到目录/platforms/android/app/,但这会生成另一个错误:

Solution proposed here in SO: Copy google-services.json to directory /platforms/android/app/, but this generated another error:

:app:mergeDebugResources失败

:app:mergeDebugResources FAILED

失败:构建失败,并出现异常.

FAILURE: Build failed with an exception.

  • 出了什么问题: 任务':app:mergeDebugResources'的执行失败.
  • What went wrong: Execution failed for task ':app:mergeDebugResources'.

[string/google_app_id]/myAppCordova2/platforms/android/app/src/main/res/values/strings.xml [string/google_app_id]/myAppCordova2/platforms/android/app/build/generation/res/google- services/debug/values/values.xml:错误:资源重复 [string/google_api_key]/myAppCordova2/platforms/android/app/src/main/res/values/strings.xml [string/google_api_key]/myAppCordova2/platforms/android/app/build/generated/res/google-services/debug/values/values.xml:错误:资源重复

[string/google_app_id] /myAppCordova2/platforms/android/app/src/main/res/values/strings.xml [string/google_app_id] /myAppCordova2/platforms/android/app/build/generated/res/google-services/debug/values/values.xml: Error: Duplicate resources [string/google_api_key] /myAppCordova2/platforms/android/app/src/main/res/values/strings.xml [string/google_api_key] /myAppCordova2/platforms/android/app/build/generated/res/google-services/debug/values/values.xml: Error: Duplicate resources

PS: 我尝试了在SO中提出的几个修复程序,但都没有解决我的问题,有人可以帮助我吗?

PS: I tried several fixes proposed here in the SO and none solved my problem, could anyone help me?

推荐答案

我找到了解决问题的方法:

此处提供了与我遵循的(和引起问题的)类似的指令,尽管相关性的版本有些过时:

Instructions similar to those I followed (and that caused the problem) are available here, although with the versions of the dependencies a bit outdated:

https://firebase.google.com/docs/android/setup

造成我这种情况的原因是,按照Firebase中应用程序创建"页面上的这些说明进行操作,并将依赖项添加到项目和模块的build.gradle文件中,如下所示:

What caused the problem in my case was to follow these instructions on the App creation page in Firebase and add the dependencies in the build.gradle files of the project and module as can be seen below:

添加项目build.gradle /project/platforms/android/build.gradle:

Add in project build.gradle /project/platforms/android/build.gradle:

buildscript {
    repositories {
        jcenter ()
        maven {
            url "https://maven.google.com"
        }
        Google()
    }
    dependencies {

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.android.tools.build:gradle:3.1.3'

        // Firebase
        classpath 'com.google.gms: google-services: 4.0.0'
    }
}

并添加模块build.gradle /project/platforms/android/app/build.gradle:

And add in module build.gradle /project/platforms/android/app/build.gradle:

buildscript {
    repositories {
        mavenCentral ()
        jcenter ()
        maven {
            url "https://maven.google.com"
        }
        Google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'

        // Firebase
        classpath 'com.google.gms: google-services: 4.0.0'
        classpath 'com.google.firebase: firebase-core: 16.0.0'
    }
}

// Firebase, add at the end of the same file
apply plugin: 'com.google.gms.google-services'


解决方案:

我找到的解决方案是对注释// Firebase之前的行进行注释:

The solution I found was to comment the lines that are preceded by the comment // Firebase:

文件:/project/platforms/android/build.gradle:

buildscript {
    repositories {
        jcenter ()
        maven {
            url "https://maven.google.com"
        }
        Google()
    }
    dependencies {

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.android.tools.build:gradle:3.1.3'

        // Firebase
        // classpath 'com.google.gms: google-services: 4.0.0'
    }
}

文件:/project/platforms/android/app/build.gradle:

    buildscript {
        repositories {
            mavenCentral ()
            jcenter ()
            maven {
                url "https://maven.google.com"
            }
            Google()
        }

        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.3'

            // Firebase
            //classpath 'com.google.gms: google-services: 4.0.0'
            //classpath 'com.google.firebase: firebase-core: 16.0.0'
        }
    }

// Firebase, add at the end of the same file
//apply plugin: 'com.google.gms.google-services'

完成这些步骤后,一切正常,我能够毫无问题地运行$ cordova build android.

After these steps, everything worked fine and I was able to run $ cordova build android without problems.

建议: 如果发生任何其他错误,请尝试删除插件和平台,然后重新创建它们:

Suggestion: If any other errors occur, try removing the plugins and platform, then re-create them:

$ cordova plugin rm cordova-plugin-firebase
$ cordova platform rm android

$ cordova plugin add cordova-plugin-firebase
$ cordova platform add android

这篇关于在添加和配置"cordova-plugin-firebase"后,在应用程序(cordova build android)中执行构建时出错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆