0
votes

I created an App using Cordova, then followed the instructions to prepare the App to integrate with the Firebase plugin:

  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.

After following the plugin and firebase documentation, I came across this error:

:app:processDebugGoogleServices FAILED

FAILURE: Build failed with an exception.

* 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

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

:app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

  • 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/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: I tried several fixes proposed here in the SO and none solved my problem, could anyone help me?

1
I had a similar error and had to delete some lines from strings.xml, see this link for details - John M
Thanks for your answer, in my case, what solved the problem was to remove the Firebase dependencies from the build.gradle files, as I explained in my answer below. - Cleberson Falk

1 Answers

1
votes

I found a solution to problem:

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

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:

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'
    }
}

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'

Solution:

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

File: /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'
    }
}

File: /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'

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