2017-01-31 84 views
1

我正嘗試在我的框架項目中添加Firebase。我也跟着下面的鏈接 https://medium.com/@RICEaaron/scala-firebase-da433df93bd2#.m1fwlvc8l無法在Play框架工作應用程序中導入com.google.firebase.FirebaseApplication

我跟以下步驟

    在火力開發者控制檯
  1. 產生的私人服務器密鑰
  2. 創建的項目和下載的JSON文件
  3. 增加火力服務器SDK依賴於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" 
) 

現在我想初始化這個代碼片斷的火力地堡服務器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

(與您的問題無關)PDFBox現在是2.0.4。 –

回答

2

你的火力地堡服務器SDK的依賴是老:

"com.google.firebase" % "firebase-server-sdk" % "3.0.1" 

對於通過firebase.google.com創造了新的火力地堡的項目,你應該在JVM上運行時,可以使用Firebase Admin SDK。 maven依賴項是com.google.firebase:firebase-admin:4.1.0

該SDK中沒有FirebaseApplication - 也許您正在尋找?

+0

感謝您的幫助。其實我需要運行一個命令激活eclipse並重新啓動eclipse來導入com.google.firebase.FirebaseApp工作。感謝您告訴我有關最新版本的Firebase SDK的信息。 –

相關問題