Error when building the app (Cordova build android), after adding and configuring the "Cordova-plugin-firebase"

Asked

Viewed 547 times

0

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

  1. I created the Keystore (needed to integrate with Firebase).
  2. Then I created the application project in Firebase and informed the hash stored in the Keystore.
  3. Then I installed the plugin cordova-plugin-firebase.
  4. And copy the google-services.json file to the project root folder.

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/null/debug/google-services.json /myAppCordova2/Platforms/android/app/src/debug/null/google-services.json /myAppCordova2/Platforms/android/app/src/null/google-services.json /myAppCordova2/Platforms/android/app/src/debug/google-services.json
/myAppCordova2/Platforms/android/app/src/nullDebug/google-services.json /myAppCordova2/Platforms/android/app/google-services.json

Solution proposed here in the OS: copy the google-services.json to the 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’ve tried several solutions proposed here in the OS and none solved my problem, anyone could help me?

1 answer

0


I found a solution to the problem:

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

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

What caused the problem in my case was following these instructions on the Firebase app creation page and adding dependencies to the files build.gradle design and module, as can be seen below:

File build.gradle of the project /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 to file build.gradle module /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 on the lines preceded by the comment // Firebase:

Filing cabinet /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'
    }
}

Filing cabinet /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 well and I could rotate $ cordova build android hassle-free.


Suggestion: If any other error occurs, try removing the plugins and the platform and then recreate them:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.