NoSuchMethodError: While integrating Firebase with app engine app

ⅰ亾dé卋堺 提交于 2020-01-01 12:31:07

问题


I was trying to integrate firebase real time database with google app engine app. I was getting this error when calling

> DatabaseReference ref = FirebaseDatabase
>                   .getInstance()
>                   .getReference("todoItems");

Stacktrace is

03:21:01.450 Error for /productSync java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V at com.google.firebase.FirebaseApp.checkNotDeleted(FirebaseApp.java:314) at com.google.firebase.FirebaseApp.getOptions(FirebaseApp.java:260) at com.google.firebase.database.FirebaseDatabase.getInstance(FirebaseDatabase.java:80) at in.prago.servlet.ProductDataSync.doGet(ProductDataSync.java:83) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:37) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:257) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:145) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest(JavaRuntime.java:644) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest(JavaRuntime.java:604) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:574) at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:453) at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:460) at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:293) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:319) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:311) at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:457) at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:238) at java.lang.Thread.run(Thread.java:745)

This same problem has been discussed in many forums where people suggested to upgrade Guava 19.0 to Guava 20.0. In my case I was not using any such library, therefore I tried adding both, but it didn't worked out for me. Same error was there every time. I am also adding my pom.xml file just in case someone needs to have a look at it. Any help would be appreciated.

Here is a link to one such forum https://github.com/google/guava/issues/2380

<?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>
    <packaging>war</packaging>
    <version>1.0</version>


    <properties>
        <appengine.app.version>1</appengine.app.version>
        <appengine.target.version>1.9.53</appengine.target.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

     <dependency>
  <groupId>com.google.firebase</groupId>
  <artifactId>firebase-admin</artifactId>
  <version>5.0.0</version>
</dependency>

<dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>20.0</version>
    </dependency>

        <!-- Compile/runtime dependencies -->
        <dependency>
    <groupId>com.google.endpoints</groupId>
    <artifactId>endpoints-framework</artifactId>
    <version>2.0.7</version>
</dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-1.0-sdk</artifactId>
            <version>${appengine.target.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-endpoints</artifactId>
            <version>${appengine.target.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.objectify</groupId>
            <artifactId>objectify</artifactId>
            <version>5.0</version>
        </dependency>

        <dependency>
    <groupId>com.google.endpoints</groupId>
    <artifactId>endpoints-management-control-appengine</artifactId>
    <version>1.0.0-beta.11</version>
</dependency>
<dependency>
    <groupId>com.google.endpoints</groupId>
    <artifactId>endpoints-framework-auth</artifactId>
    <version>1.0.0-beta.11</version>
</dependency>



        <!-- Test Dependencies -->
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-testing</artifactId>
            <version>${appengine.target.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-stubs</artifactId>
            <version>${appengine.target.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>



    </dependencies>

    <build>
        <outputDirectory>target/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <version>2.5.1</version>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>endpoints-framework-maven-plugin</artifactId>
    <version>1.0.0-beta5</version>
    <configuration>
        <!-- plugin configuration -->
    </configuration>
</plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
                            <!-- the list has a default value of ** -->
                            <includes>
                                <include>WEB-INF/*.discovery</include>
                                <include>WEB-INF/*.api</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${appengine.target.version}</version>
                <configuration>
                    <enableJarClasses>false</enableJarClasses>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>endpoints_get_discovery_doc</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            com.google.appengine
                                        </groupId>
                                        <artifactId>
                                            appengine-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [1.9.3,)
                                        </versionRange>
                                        <goals>
                                            <goal>
                                                endpoints_get_discovery_doc
                                            </goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <groupId>in.prago</groupId>
    <artifactId>prago</artifactId>
</project>

Update :

As suggested by Auberon I updated my pom.xml with new version of Objectify 5.1.17 and removed the guava depedency. I tried running the code but the same error coined up again. Here is my stacktrace

> com.google.api.server.spi.SystemService invokeServiceMethod: exception
> occurred while calling backend method (SystemService.java:398)
> 
> java.lang.NoSuchMethodError:
> com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
>   at
> com.google.firebase.FirebaseApp.checkNotDeleted(FirebaseApp.java:314)
>   at com.google.firebase.FirebaseApp.getOptions(FirebaseApp.java:260)
>   at
> com.google.firebase.database.FirebaseDatabase.getInstance(FirebaseDatabase.java:80)
>   at
> in.prago.spi.PragoMerchantApi.saveProfile(PragoMerchantApi.java:189)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>   at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:42)  at
> com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:363)
>   at
> com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:113)
>   at
> com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:71)
>   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)     at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)  at
> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
>   at
> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
>   at
> com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
>   at
> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
>   at
> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
>   at
> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
>   at
> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
>   at
> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
>   at
> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
>   at
> org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
>   at
> org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
>   at
> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
>   at
> org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
>   at
> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
>   at org.mortbay.jetty.Server.handle(Server.java:326)     at
> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
>   at
> org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
>   at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
>   at
> com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:453)
>   at
> com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:460)
>   at
> com.google.tracing.CurrentContext.runInContext(CurrentContext.java:293)
>   at
> com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:319)
>   at
> com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:311)
>   at
> com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:457)
>   at java.lang.Thread.run(Thread.java:745)

http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <packaging>war</packaging>
    <version>1.0</version>


    <properties>
        <appengine.app.version>1</appengine.app.version>
        <appengine.target.version>1.9.53</appengine.target.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

     <dependency>
  <groupId>com.google.firebase</groupId>
  <artifactId>firebase-admin</artifactId>
  <version>5.0.0</version>
</dependency>

<dependency>

    <groupId>com.google.endpoints</groupId>
    <artifactId>endpoints-framework</artifactId>
    <version>2.0.7</version>
</dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-1.0-sdk</artifactId>
            <version>${appengine.target.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-endpoints</artifactId>
            <version>${appengine.target.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.objectify</groupId>
            <artifactId>objectify</artifactId>
            <version>5.1.17</version>
        </dependency>

        <dependency>
    <groupId>com.google.endpoints</groupId>
    <artifactId>endpoints-management-control-appengine</artifactId>
    <version>1.0.0-beta.11</version>
</dependency>
<dependency>
    <groupId>com.google.endpoints</groupId>
    <artifactId>endpoints-framework-auth</artifactId>
    <version>1.0.0-beta.11</version>
</dependency>



        <!-- Test Dependencies -->
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-testing</artifactId>
            <version>${appengine.target.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-stubs</artifactId>
            <version>${appengine.target.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>



    </dependencies>

    <build>
        <outputDirectory>target/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <version>2.5.1</version>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>endpoints-framework-maven-plugin</artifactId>
    <version>1.0.0-beta5</version>
    <configuration>
        <!-- plugin configuration -->
    </configuration>
</plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
                            <!-- the list has a default value of ** -->
                            <includes>
                                <include>WEB-INF/*.discovery</include>
                                <include>WEB-INF/*.api</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${appengine.target.version}</version>
                <configuration>
                    <enableJarClasses>false</enableJarClasses>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>endpoints_get_discovery_doc</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            com.google.appengine
                                        </groupId>
                                        <artifactId>
                                            appengine-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [1.9.3,)
                                        </versionRange>
                                        <goals>
                                            <goal>
                                                endpoints_get_discovery_doc
                                            </goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <groupId>in.prago</groupId>
    <artifactId>prago</artifactId>
</project>

回答1:


Include on project Guava newer version dependence.

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>22.0</version>
</dependency>



回答2:


I also ran into this error and I never used Guava either. Funnily enough, my Glassfish server was using it's Guava version over the imported one! Run this code before the error to find out where your problematic Guava is coming from.

System.out.println(com.google.common.base.Preconditions.class.getProtectionDomain().getCodeSource().getLocation().toExternalForm());

Then download the most recent guava (currently Guava 22.0) and replace the old Guava file with the new one. This should fix your issue.

At this point, you should also be using the newer firebase version as well. I believe the developer also had the wrong Guava version in a previous firebase version.

        <dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-admin</artifactId>
        <version>5.2.0</version>
        </dependency>


来源:https://stackoverflow.com/questions/44170175/nosuchmethoderror-while-integrating-firebase-with-app-engine-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!