NoSuchMethodError: While integrating Firebase with app engine app

NoSuchMethodError: While integrating Firebase with app engine app

我试图将 firebase 实时数据库与 google 应用引擎应用集成。我在调用

时收到此错误
> DatabaseReference ref = FirebaseDatabase
>                   .getInstance()
>                   .getReference("todoItems");

堆栈跟踪是

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.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)

同样的问题已经在许多论坛中讨论过,人们建议将 Guava 19.0 升级到 Guava 20.0。在我的例子中,我没有使用任何这样的库,因此我尝试添加两者,但它对我来说没有用。每次都出现同样的错误。我还添加了我的 pom.xml 文件,以防万一有人需要查看它。任何帮助,将不胜感激。

这是一个 link 这样的论坛 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>

更新:

按照 Auberon 的建议,我用新版本的 Objectify 5.1.17 更新了我的 pom.xml 并删除了 guava depedency。我尝试了 运行 代码,但同样的错误又出现了。这是我的堆栈跟踪

> 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.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>

我也 运行 遇到了这个错误,而且我也从未使用过 Guava。有趣的是,我的 Glassfish 服务器使用的是 Guava 版本而不是导入版本! 运行 错误前的这段代码可以找出有问题的番石榴来自哪里。

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

然后下载最新的 guava(当前 Guava 22.0)并用新文件替换旧的 Guava 文件。这应该可以解决您的问题。

此时,您也应该使用较新的 firebase 版本。我相信开发人员在以前的 firebase 版本中也有错误的 Guava 版本。

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

在您的 pom 中包含更新版本的 Guava。

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