Cordova-plugin-firebase: Error since firebase update on March 20th. Would you set firebase sdk version?

Created on 22 Mar 2018  ·  21Comments  ·  Source: arnesson/cordova-plugin-firebase

Since : https://firebase.google.com/support/releases March 20th.

Error

AndroidRuntime: java.lang.NoSuchMethodError: No static method zza(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzbq; or its super classes (declaration of 'com.google.android.gms.common.internal.zzbq'

Most helpful comment

I solved by updating platforms/android/build.gradle
Before

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

After:

allprojects {
    repositories {
        //start here
        configurations.all {
            resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                def requested = details.requested
                if (requested.group == 'com.google.android.gms') {
                    details.useVersion '11.8.0'
                }
                if (requested.group == 'com.google.firebase') {
                    details.useVersion '11.8.0'
                }
            }
        }
        //end
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

Tested on [email protected]

All 21 comments

this is a critical issue.

Hi, I have other error due to the same firebase update. When I type:

cordova build android

in the console, I get this output:

BUILD FAILED

Total time: 4.529 secs
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':processDebugResources'.
    > Error: more than one library with package name 'com.google.android.gms.license'`

I have been looking for the answer through the web but the solutions I found (solution1, solution2, solution3) doesn't work for me.

The error appears to be due to the Play Services update. I cannot build my android app until I have remove this plugin.

I hope this critical issue could be solve to install the plugin again.

there is a temporary fix to this, force the services and firebase versions to 11.8.0.

how to:
put this inside the tag of config.xml with the content:

<hook src="fixFirebasePlugin.js" type="before_build" />

create the JS file on your project root:

module.exports = function(context) {
    var fs = require('fs');
    var path = require('path');

    var rootdir = context.opts.projectRoot;

    var platformDir = 'platforms/android';
        //change the path to your external gradle file
    var srcFile = path.join(rootdir, 'src/android/build-extras.gradle');
    var destFile = path.join(rootdir, platformDir, 'build-extras.gradle');

    console.log("copying "+srcFile+" to "+destFile);
    fs.createReadStream(srcFile).pipe(fs.createWriteStream(destFile));
}

create inside the src folder a android fodler and create inside that a file called build-extras.gradle with the content:

configurations.all {
   resolutionStrategy {
       force "com.google.android.gms:play-services-ads:11.8.0"
       force "com.google.android.gms:play-services-base:11.8.0"
       force "com.google.android.gms:play-services-gcm:11.8.0"
       force "com.google.android.gms:play-services-analytics:11.8.0"
       force "com.google.android.gms:play-services-location:11.8.0"
       force "com.google.android.gms:play-services-basement:11.8.0"
       force "com.google.android.gms:play-services-tagmanager:11.8.0"
       force 'com.google.firebase:firebase-core:11.8.0'
       force 'com.google.firebase:firebase-crash:11.8.0'
       force 'com.google.firebase:firebase-auth:11.8.0'
       force 'com.google.firebase:firebase-common:11.8.0'
       force 'com.google.firebase:firebase-config:11.8.0'
       force 'com.google.firebase:firebase-messaging:11.8.0'
   }
}

remove and re add platform (tested on 6.3.0), perform a cordova build android, and it's fixed.

after that, a run/build --prod, whatever you want.

@tryadelion, I have tried your solution exactly as you mentioned, but I got the same error in console :(

have you removed the platform, readded as [email protected] and performed a "~: cordova build android", no prod, no run, no ionic? that's what did the trick for me!

Yes, I did everything (config.xml, fixFirebasePlugin.js, build-extras.gradle, platform [email protected]), but every run or build command I execute produce the same output:

firebase-build-failed

My project is not an ionic one, I don't know if this could be important to this issue.

did you try any prior "hotfix" to this? like hand-changing the versions on the plugin's XML? i had to remove and readd it because i messed with it's files. it has worked so far on 3 different projects, all ionic though, but the hook system is the same as it's cordova powered.

Before that, I have only changed /platforms/android/project.properties and /platforms/android/build.gradle but after that I have removed and re-added the plugin (first), and the platform [email protected]. (after).

I don't know what could be the reason of the fail, butI think my project still have both versions: 12.0 and 11.8.0 because in the console I see this:

firebase-build-failed-2

I don't know where could be specified the 12.0.0 version.

remove node-modules, remove platforms/android, remove every services-using plugin in /plugins, NPM i, readd every plugin that you removed, add platform android, and try again. that's what i would do.

Ok, I'll try to re-install every component I have. Thank you very much for your help!!

@tryadelion Thanks for sharing. I was about to fork cordova-plugin-firebase and force versions. Anyway, i implemented your solution.

We are working with [email protected] that is working as well.

Finally I solve the problem modifying the file /platforms/android/build.gradle this way:

allprojects {

    repositories {
    // Temp fix for com.google.android.gms.license
            // Added from here
            configurations.all {
                resolutionStrategy {

                    // Put your gms packages here with 11.8.0 attached
                    force "com.google.android.gms:play-services-analytics:11.8.0"
                    force "com.google.android.gms:play-services-auth:11.8.0"
                    force "com.google.android.gms:play-services-gcm:11.8.0"
                    force "com.google.android.gms:play-services-location:11.8.0"
                }
            }
            // until here

        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

(Solution read from https://github.com/facebook/react-native/issues/18479)

Thanks again!

For Ionic v1.1.0 andcordova-plugin-firebase v0.1.25 this hook solved my problem:

//before_build/010_add_gradle_extras.js

#!/usr/bin/env node

var fs = require('fs');
var path = require('path');

var rootdir = process.argv[2];
var platformDir = 'platforms/android';

var srcfile = path.join(rootdir, 'build-extras.gradle');
var destfile = path.join(rootdir, platformDir, 'build-extras.gradle');
var destdir = path.dirname(destfile);

if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
  fs.createReadStream(srcfile).pipe(fs.createWriteStream(destfile));
  process.stdout.write('Hook: build-extras.gradle added');
} 
//build-extras.gradle

configurations.all {
   resolutionStrategy {
       force "com.google.android.gms:play-services-ads:11.8.0"
       force "com.google.android.gms:play-services-base:11.8.0"
       force "com.google.android.gms:play-services-gcm:11.8.0"
       force "com.google.android.gms:play-services-analytics:11.8.0"
       force "com.google.android.gms:play-services-location:11.8.0"
       force "com.google.android.gms:play-services-basement:11.8.0"
       force "com.google.android.gms:play-services-tagmanager:11.8.0"
       force 'com.google.firebase:firebase-core:11.8.0'
       force 'com.google.firebase:firebase-crash:11.8.0'
       force 'com.google.firebase:firebase-auth:11.8.0'
       force 'com.google.firebase:firebase-common:11.8.0'
       force 'com.google.firebase:firebase-config:11.8.0'
       force 'com.google.firebase:firebase-messaging:11.8.0'
   }
}

Remove and adding new android platform was also a key factor.

@tryadelion, any idea why I get this error when I try your approach?

A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_debugApkCopy'.
   > Could not find com.google.gms:google-services:11.8.0.
     Required by:
         project :

I did what jotefer said and it makes the build work. However, remote config stopped working. Any idea?

Diving into the issue that fetch is not working I found out that it's because of the following exception which is being thrown when calling fetch:

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.util.ArraySet" on path: DexPathList

Any idea?

@remisture i had that issue happen when another gradle file was still referencing 12.X, try build cleaning.

I solved by updating platforms/android/build.gradle
Before

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

After:

allprojects {
    repositories {
        //start here
        configurations.all {
            resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                def requested = details.requested
                if (requested.group == 'com.google.android.gms') {
                    details.useVersion '11.8.0'
                }
                if (requested.group == 'com.google.firebase') {
                    details.useVersion '11.8.0'
                }
            }
        }
        //end
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

Tested on [email protected]

Below is my entire build.gradle. Also has a useful bit at the end for changing the compile sdk for all projects

buildscript {
    repositories {
        jcenter()
        google()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        configurations.all {
            resolutionStrategy.eachDependency { DependencyResolveDetails details ->
                def requested = details.requested
                if (requested.group == 'com.google.android.gms') {
                    details.useVersion '12.0.1'
                }
            }
        }
        mavenLocal()
        jcenter()
        maven {
            url "https://jitpack.io"
        }
        maven {
            url 'https://maven.google.com'
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 26
                buildToolsVersion '26.0.2'
            }
        }
    }
}

this appears to be fixed by installing cordova-android-play-services-gradle-release

@soumak77 that works thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JonSmart picture JonSmart  ·  3Comments

DanielAccorsi picture DanielAccorsi  ·  3Comments

stephan-nordnes-eriksen picture stephan-nordnes-eriksen  ·  5Comments

ulisesvera picture ulisesvera  ·  5Comments

LKruglov picture LKruglov  ·  4Comments