【问题标题】:Error executing the build in the app (cordova build android), after adding and configuring "cordova-plugin-firebase"添加和配置“cordova-plugin-firebase”后,在应用程序中执行构建时出错(cordova build android)
【发布时间】:2018-12-31 09:27:50
【问题描述】:

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

  1. 创建了密钥库(需要与 Firebase 集成)。
  2. 我在 Firebase 中创建了应用程序的项目并通知了哈希 存储在密钥库中。
  3. 我安装了插件“cordova-plugin-firebase”。
  4. 将文件 google-services.json 复制到 项目。

在关注插件和 firebase 文档后,我遇到了这个错误:

:app:processDebugGoogleServices 失败

FAILURE:构建失败并出现异常。

* 出了什么问题: 任务“:app:processDebugGoogleServices”执行失败。 > 文件 google-services.json 丢失。没有它,Google 服务插件无法 > 运行。 搜索位置: /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/,但这又产生了一个错误:

:app:mergeDebugResources 失败

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务 ':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/generated/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:错误:资源重复

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

【问题讨论】:

  • 我遇到了类似的错误,不得不从 strings.xml 中删除一些行,详情请参阅this link
  • 感谢您的回答,就我而言,解决问题的方法是从 build.gradle 文件中删除 Firebase 依赖项,正如我在下面的回答中所解释的那样。

标签: android cordova firebase


【解决方案1】:

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

此处提供了与我遵循的类似说明(以及导致问题的说明),尽管依赖项的版本有点过时:

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

在我的情况下导致问题的原因是按照 Firebase 中的应用程序创建页面上的这些说明,并在项目和模块的 build.gradle 文件中添加依赖项,如下所示:

在项目中添加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:

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前面的行:

文件:/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。


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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-04
    • 2018-02-12
    • 1970-01-01
    • 2019-02-15
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多