我正在用 JavaFX 構建一個簡單的程序,用于將 .xls 文件上傳到我的 firebase/firestore 項目。每次我嘗試運行該程序并單擊一個按鈕來初始化我的上傳器類時,它都會失敗并顯示一條錯誤消息:FirebaseApp 名稱 [DEFAULT] 已經存在!找了半天,還是沒找到有用的。我已經嘗試過 OAuth2 令牌(在 Google Cloud 中創建了一個服務帳戶,獲得了 JSON 文件)、環境變量(不會檢測到),以及文檔中的幾乎所有內容。 FileInputStream serviceAccount = new FileInputStream("<path>.json");FirebaseOptions options = new FirebaseOptions.Builder() .setCredentials(GoogleCredentials.fromStream(serviceAccount)) .setDatabaseUrl("https://<project>.firebaseio.com/") .build(); FirebaseApp.initializeApp(options); <----This line won't compile for some reason..Firebase app =FirebaseApp.initializeApp(options); <--------- This will compile我正在使用 Gradle 作為我的構建工具。這是我到目前為止所得到的,它似乎可以很好地構建而沒有問題。我是否缺少任何依賴項? plugins { id 'java' id 'org.openjfx.javafxplugin' version '0.0.8' id 'application'}version '1.0-SNAPSHOT'sourceCompatibility = 1.8repositories { mavenCentral() jcenter() google()}dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' compile "org.apache.poi:poi:3.17" compile "org.apache.poi:poi-ooxml:3.17" implementation 'com.google.firebase:firebase-auth:18.1.0' implementation 'com.google.firebase:firebase-admin:6.9.0' implementation 'com.google.firebase:firebase-firestore:20.2.0' compile 'com.google.firebase:firebase-admin:6.9.0'}javafx { version = '12' modules = ['javafx.controls', 'javafx.fxml']}mainClassName = 'app.Main'apply plugin: 'org.openjfx.javafxplugin'
1 回答

慕妹3242003
TA貢獻1824條經驗 獲得超6個贊
您不能firebase-admin
與其他 Firebase Android 庫一起使用,例如firebase-auth
和firebase-firestore
。您應該使用 Admin SDK 或 Android SDK,但絕不能同時使用兩者。
來到確切的錯誤消息,這表明initializeApp()
在您的應用程序中被多次調用。它正在嘗試初始化[DEFAULT]
, 當一個已經存在時。
添加回答
舉報
0/150
提交
取消