简体   繁体   中英

java.lang.NoSuchMethodError when connecting to Firebase from Java

I'm trying to connect my Java web project to Firebase, so I'll be able to store my data in Firestore. I'm using Java Admin SDK, following official guide: FirebaseAdminSDK . Sadly, I'm getting exceptions when FirebaseAp is being initialized:

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
at com.google.firebase.FirebaseApp.checkNotDeleted(FirebaseApp.java:352)
at com.google.firebase.FirebaseApp.getOptions(FirebaseApp.java:267)
at com.google.firebase.FirebaseApp$TokenRefresher.<init>(FirebaseApp.java:434)
at com.google.firebase.FirebaseApp$TokenRefresher$Factory.create(FirebaseApp.java:535)
at com.google.firebase.FirebaseApp.<init>(FirebaseApp.java:113)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:201)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:188)

Now, I read here and there, that it's problem with guava project and it is recommended to use different versions of guava library. I tried all versions starting from 18.

Then, I read that it can be caused by multiple guava libraries referenced by different libraries in my classpath in defferent versions fighting each other. So, I checked maven dependency tree to see if there are multiple dependencies on guava. Nope.

Then, I unpacked .WAR file to see what exact jars are being deployed to glassfish with my app. Only one guava jar is there (the one pointed by my pom.xml file). To be honest, I've run out of ideas. Please help. You can see pom.xml and generated maven dependency tree appended below.

pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.greenstudio</groupId>
    <artifactId>trekking-project</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>trekking-project</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.firebase</groupId>
            <artifactId>firebase-admin</artifactId>
            <version>5.6.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>guava</artifactId>
                    <groupId>com.google.guava</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>21.0</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.9.9</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.5.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
            <version>2.5.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.3.3</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.6</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.3</version>
        </dependency>
        <dependency>
            <groupId>primefaces.blacktie</groupId>
            <artifactId>primefaces.blacktie</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>bootstrap</groupId>
            <artifactId>bootstrap</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons.validator.routines.EmailValidatororg.apache.commons.validator.routines.EmailValidator</groupId>
            <artifactId>org.apache.commons.validator.routines.EmailValidator</artifactId>
            <version>1.0</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

dependency tree

[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.8/maven-dependency-plugin-2.8.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.8/maven-dependency-plugin-2.8.pom (11 kB at 18 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.8/maven-dependency-plugin-2.8.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.8/maven-dependency-plugin-2.8.jar (153 kB at 709 kB/s)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building trekking-project 1.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for primefaces:primefaces:jar:5.3 is missing, no dependency information available
[WARNING] The POM for primefaces.blacktie:primefaces.blacktie:jar:1.0 is missing, no dependency information available
[WARNING] The POM for bootstrap:bootstrap:jar:1.0 is missing, no dependency information available
[WARNING] The POM for org.apache.commons.validator.routines.EmailValidatororg.apache.commons.validator.routines.EmailValidator:org.apache.commons.validator.routines.EmailValidator:jar:1.0 is missing, no dependency information available
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ trekking-project ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.3/plexus-archiver-2.3.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.3/plexus-archiver-2.3.pom (3.4 kB at 38 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-dependency-analyzer/1.4/maven-dependency-analyzer-1.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-dependency-analyzer/1.4/maven-dependency-analyzer-1.4.pom (5.2 kB at 58 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.3/plexus-archiver-2.3.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-dependency-analyzer/1.4/maven-dependency-analyzer-1.4.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-dependency-analyzer/1.4/maven-dependency-analyzer-1.4.jar (27 kB at 105 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archiver/2.3/plexus-archiver-2.3.jar (186 kB at 704 kB/s)
[INFO] com.greenstudio:trekking-project:war:1.0
[INFO] +- com.google.firebase:firebase-admin:jar:5.6.0:compile
[INFO] |  +- com.google.api-client:google-api-client:jar:1.22.0:compile
[INFO] |  |  +- com.google.oauth-client:google-oauth-client:jar:1.22.0:compile
[INFO] |  |  \- com.google.http-client:google-http-client-jackson2:jar:1.22.0:compile
[INFO] |  |     \- com.fasterxml.jackson.core:jackson-core:jar:2.1.3:compile
[INFO] |  +- com.google.api-client:google-api-client-gson:jar:1.22.0:compile
[INFO] |  |  \- com.google.http-client:google-http-client-gson:jar:1.22.0:compile
[INFO] |  |     \- com.google.code.gson:gson:jar:2.1:compile
[INFO] |  +- com.google.http-client:google-http-client:jar:1.22.0:compile
[INFO] |  |  \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  +- com.google.api:api-common:jar:1.2.0:compile
[INFO] |  +- com.google.auth:google-auth-library-oauth2-http:jar:0.8.0:compile
[INFO] |  |  \- com.google.auth:google-auth-library-credentials:jar:0.8.0:compile
[INFO] |  +- com.google.cloud:google-cloud-storage:jar:1.7.0:compile
[INFO] |  |  +- com.google.cloud:google-cloud-core:jar:1.7.0:compile
[INFO] |  |  |  +- com.google.api:gax:jar:1.8.1:compile
[INFO] |  |  |  +- com.google.protobuf:protobuf-java-util:jar:3.3.1:compile
[INFO] |  |  |  +- com.google.api.grpc:proto-google-common-protos:jar:0.1.20:compile
[INFO] |  |  |  \- com.google.api.grpc:proto-google-iam-v1:jar:0.1.20:compile
[INFO] |  |  +- com.google.cloud:google-cloud-core-http:jar:1.7.0:compile
[INFO] |  |  |  +- com.google.http-client:google-http-client-appengine:jar:1.22.0:compile
[INFO] |  |  |  \- com.google.http-client:google-http-client-jackson:jar:1.22.0:compile
[INFO] |  |  |     \- org.codehaus.jackson:jackson-core-asl:jar:1.9.11:compile
[INFO] |  |  \- com.google.apis:google-api-services-storage:jar:v1-rev108-1.22.0:compile
[INFO] |  +- com.google.cloud:google-cloud-firestore:jar:0.25.0-beta:compile
[INFO] |  |  +- io.netty:netty-tcnative-boringssl-static:jar:2.0.3.Final:compile
[INFO] |  |  +- com.google.cloud:google-cloud-core-grpc:jar:1.7.0:compile
[INFO] |  |  |  +- com.google.protobuf:protobuf-java:jar:3.3.1:compile
[INFO] |  |  |  +- io.grpc:grpc-protobuf:jar:1.6.1:compile
[INFO] |  |  |  |  \- io.grpc:grpc-protobuf-lite:jar:1.6.1:compile
[INFO] |  |  |  \- io.grpc:grpc-context:jar:1.6.1:compile
[INFO] |  |  +- com.google.api:gax-grpc:jar:0.25.1:compile
[INFO] |  |  |  +- com.google.auto.value:auto-value:jar:1.2:compile
[INFO] |  |  |  \- org.threeten:threetenbp:jar:1.3.3:compile
[INFO] |  |  +- com.google.api.grpc:proto-google-cloud-firestore-v1beta1:jar:0.1.20:compile
[INFO] |  |  +- io.grpc:grpc-netty:jar:1.6.1:compile
[INFO] |  |  |  +- io.grpc:grpc-core:jar:1.6.1:compile (version selected from constraint [1.6.1,1.6.1])
[INFO] |  |  |  |  +- com.google.errorprone:error_prone_annotations:jar:2.0.19:compile
[INFO] |  |  |  |  +- com.google.instrumentation:instrumentation-api:jar:0.4.3:compile
[INFO] |  |  |  |  \- io.opencensus:opencensus-api:jar:0.5.1:compile
[INFO] |  |  |  +- io.netty:netty-codec-http2:jar:4.1.14.Final:compile (version selected from constraint [4.1.14.Final,4.1.14.Final])
[INFO] |  |  |  \- io.netty:netty-handler-proxy:jar:4.1.14.Final:compile
[INFO] |  |  |     \- io.netty:netty-codec-socks:jar:4.1.14.Final:compile
[INFO] |  |  +- io.grpc:grpc-stub:jar:1.6.1:compile
[INFO] |  |  \- io.grpc:grpc-auth:jar:1.6.1:compile
[INFO] |  +- org.json:json:jar:20160810:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- io.netty:netty-codec-http:jar:4.1.14.Final:compile
[INFO] |  |  \- io.netty:netty-codec:jar:4.1.14.Final:compile
[INFO] |  +- io.netty:netty-handler:jar:4.1.14.Final:compile
[INFO] |  |  \- io.netty:netty-buffer:jar:4.1.14.Final:compile
[INFO] |  |     \- io.netty:netty-common:jar:4.1.14.Final:compile
[INFO] |  \- io.netty:netty-transport:jar:4.1.14.Final:compile
[INFO] |     \- io.netty:netty-resolver:jar:4.1.14.Final:compile
[INFO] +- com.google.guava:guava:jar:21.0:compile
[INFO] +- joda-time:joda-time:jar:2.9.9:compile
[INFO] +- org.eclipse.persistence:eclipselink:jar:2.5.2:provided
[INFO] |  +- org.eclipse.persistence:javax.persistence:jar:2.1.0:provided
[INFO] |  \- org.eclipse.persistence:commonj.sdo:jar:2.1.1:provided
[INFO] +- org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor:jar:2.5.2:provided
[INFO] |  +- org.eclipse.persistence:org.eclipse.persistence.core:jar:2.5.2:provided
[INFO] |  |  \- org.eclipse.persistence:org.eclipse.persistence.asm:jar:2.5.2:provided
[INFO] |  \- org.eclipse.persistence:org.eclipse.persistence.jpa:jar:2.5.2:provided
[INFO] |     +- org.eclipse.persistence:org.eclipse.persistence.antlr:jar:2.5.2:provided
[INFO] |     \- org.eclipse.persistence:org.eclipse.persistence.jpa.jpql:jar:2.5.2:provided
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.3.3:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.6:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- primefaces:primefaces:jar:5.3:compile
[INFO] +- primefaces.blacktie:primefaces.blacktie:jar:1.0:compile
[INFO] +- bootstrap:bootstrap:jar:1.0:compile
[INFO] +- org.apache.commons.validator.routines.EmailValidatororg.apache.commons.validator.routines.EmailValidator:org.apache.commons.validator.routines.EmailValidator:jar:1.0:compile
[INFO] \- javax:javaee-web-api:jar:7.0:provided
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.897 s
[INFO] Finished at: 2018-01-12T10:16:59+01:00
[INFO] Final Memory: 15M/215M
[INFO] ------------------------------------------------------------------------

I even downloaded github repository of google firebase sdk and got rid of all guava code references there, but then I'm getting similar errors when trying to read/write Firestore. It seems that some other google libraries depend on that crappy little jar as well.

I had the same problem with Guava versions in different dependencies.

I resolved this in Gradle like this :

configurations.all {
    resolutionStrategy {
        force 'com.google.guava:guava:17.0'
    }
}

There should be a Maven way, otherwise exclude Guava from all your dependencies and add it explicitly with your version.

It enforces Guava version globally. Fortunatelly for me, version 17 was compatible with all my dependencies. Neither 16- nor 18+ were... Sad thing these are using Guava.

Hope it helps, Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM