我正在尝试在我的Play框架项目中添加Firebase。我按照以下链接 https://medium.com/@RICEaaron/scala-firebase-da433df93bd2#.m1fwlvc8l
我完成了以下步骤
build.sbt
这是我的build.sbt代码:
name := """NeutrinoRPM"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.1"
resolvers += Resolver.sonatypeRepo("snapshots")
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
javaCore,
"ws.securesocial" %% "securesocial" % "3.0-M3",
"org.julienrf" %% "play-jsmessages" % "1.6.2",
javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.0-api"),
"org.hibernate" % "hibernate-entitymanager" % "4.3.4.Final",
"mysql" % "mysql-connector-java" % "5.1.9",
"com.typesafe.play" %% "play-mailer" % "2.4.0",
"com.nimbusds" % "nimbus-jose-jwt" % "3.8.2",
"com.wordnik" %% "swagger-play2" % "1.3.12",
"org.webjars" % "swagger-ui" % "2.1.8-M1",
"com.google.api-client" % "google-api-client" % "1.21.0",
"com.google.apis" % "google-api-services-analytics" % "v3-rev127-1.21.0",
"com.google.code.gson" % "gson" % "2.6.2",
"com.google.http-client" % "google-http-client-gson" % "1.21.0",
"org.apache.pdfbox" % "pdfbox" % "2.0.1",
"com.google.firebase" % "firebase-server-sdk" % "3.0.1"
)
现在,我正尝试使用以下代码段初始化Firebase服务器SDK:
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(选项);
但是当我尝试导入
时com.google.firebase.FirebaseApplication
com.google.firebase.FirebaseOptions
com.google.firebase.database
我收到此错误:The import com.google.firebase.FirebaseApplication can not be resolved
我花了太多时间在谷歌搜索我的问题的解决方案但最终没有任何帮助。请帮我。
答案 0 :(得分:2)
您对Firebase服务器SDK的依赖程度是旧的:
"com.google.firebase" % "firebase-server-sdk" % "3.0.1"
对于通过firebase.google.com创建的新Firebase项目,您应该在JVM中运行时使用Firebase Admin SDK。 maven依赖是com.google.firebase:firebase-admin:4.1.0
。
该SDK中没有FirebaseApplication - 也许您正在寻找FirebaseApp?