Firebase 上无法初始化 class FirebaseThreadManagers 错误
Could not initialize class FirebaseThreadManagers error on Firebase
我正在尝试从 Google App Engine 操作我的 Firebase 数据库。按照教程进行操作后,我收到以下错误 -
java.lang.NoClassDefFoundError: Could not initialize class com.google.firebase.internal.FirebaseThreadManagers
有时我会看到以下内容:
org.slf4j.LoggerFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
错误发生在 FirebaseOptions,如下面的代码所示。
FileInputStream serviceAccount = new FileInputStream("WEB-INF/MyApp.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://MyApp.firebaseio.com")
.build();
FirebaseApp.initializeApp(options);
这是完整的错误
java.lang.NoClassDefFoundError: Could not initialize class com.google.firebase.internal.FirebaseThreadManagers
at com.google.firebase.FirebaseOptions$Builder.(FirebaseOptions.java:147)
at com.example.name.myapplication.backend.MyServlet.doGet(MyServlet.java:55)
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.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doRedirectedModuleRequest(DevAppServerModulesFilter.java:415)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:128)
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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
at com.google.appengine.tools.development.JettyContainerService.forwardToServer(JettyContainerService.java:458)
at com.google.appengine.tools.development.Modules.forwardToInstance(Modules.java:372)
at com.google.appengine.tools.development.DelegatingModulesFilterHelper.forwardToInstance(DelegatingModulesFilterHelper.java:95)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doRedirect(DevAppServerModulesFilter.java:326)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:119)
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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:511)
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.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
这是我的 build.gradle 后端
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.firebase:firebase-admin:5.5.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.google.code.gson:gson:2.6.1'
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
}
顶级构建文件:
buildscript {
repositories {
jcenter()
}
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
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
不要在服务器应用中将 firebase-admin 依赖项与其他 Android 客户端库一起使用。仅 firebase-admin 就拥有在 JVM 运行时中访问实时数据库所需的一切。 Android 客户端库在服务器应用程序中没有用处,因为它们需要 Android 基础设施。
关于这行代码,我有同样的错误 NoClassDefFoundError FirebaseThreadManagers:private ThreadManager threadManager = FirebaseThreadManagers.DEFAULT_THREAD_MANAGER;
解决方案
重建 gradle 文件。 gradle 文件按预期重建 Kotlin 应用 运行。
我正在尝试从 Google App Engine 操作我的 Firebase 数据库。按照教程进行操作后,我收到以下错误 -
java.lang.NoClassDefFoundError: Could not initialize class com.google.firebase.internal.FirebaseThreadManagers
有时我会看到以下内容:
org.slf4j.LoggerFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
错误发生在 FirebaseOptions,如下面的代码所示。
FileInputStream serviceAccount = new FileInputStream("WEB-INF/MyApp.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://MyApp.firebaseio.com")
.build();
FirebaseApp.initializeApp(options);
这是完整的错误
java.lang.NoClassDefFoundError: Could not initialize class com.google.firebase.internal.FirebaseThreadManagers at com.google.firebase.FirebaseOptions$Builder.(FirebaseOptions.java:147) at com.example.name.myapplication.backend.MyServlet.doGet(MyServlet.java:55) 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.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.appengine.tools.development.DevAppServerModulesFilter.doRedirectedModuleRequest(DevAppServerModulesFilter.java:415) at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:128) 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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98) at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327) at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126) at com.google.appengine.tools.development.JettyContainerService.forwardToServer(JettyContainerService.java:458) at com.google.appengine.tools.development.Modules.forwardToInstance(Modules.java:372) at com.google.appengine.tools.development.DelegatingModulesFilterHelper.forwardToInstance(DelegatingModulesFilterHelper.java:95) at com.google.appengine.tools.development.DevAppServerModulesFilter.doRedirect(DevAppServerModulesFilter.java:326) at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:119) 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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:511) 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.HttpParser.parseNext(HttpParser.java:547) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
这是我的 build.gradle 后端
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.firebase:firebase-admin:5.5.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.google.code.gson:gson:2.6.1'
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
}
顶级构建文件:
buildscript {
repositories {
jcenter()
}
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
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
不要在服务器应用中将 firebase-admin 依赖项与其他 Android 客户端库一起使用。仅 firebase-admin 就拥有在 JVM 运行时中访问实时数据库所需的一切。 Android 客户端库在服务器应用程序中没有用处,因为它们需要 Android 基础设施。
关于这行代码,我有同样的错误 NoClassDefFoundError FirebaseThreadManagers:private ThreadManager threadManager = FirebaseThreadManagers.DEFAULT_THREAD_MANAGER;
解决方案
重建 gradle 文件。 gradle 文件按预期重建 Kotlin 应用 运行。