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

0

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

  • I created the keystore (needed to integrate with the Firebase).
  • Then I created the application project in Firebase and reported the hash stored in the keystore.
  • Then I installed the plugin cordova-plugin-firebase .
  • And copy the google-services.json file 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 can not 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 OS: copy google-services.json to /platforms/android/app/ directory, 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 have tried several solutions proposed here in the OS and none solved my problem, could anyone help me?

        
    asked by anonymous 23.07.2018 / 23:20

    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 somewhat outdated versions of the dependencies:

      

    link

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

    Add file build.gradle of 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 of 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 the lines 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 with no problems.

    Tip: If any other error occurs, try removing the plug-ins 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
    
        
    24.07.2018 / 20:26