我正在用 JavaFX 構(gòu)建一個(gè)簡(jiǎn)單的程序,用于將 .xls 文件上傳到我的 firebase/firestore 項(xiàng)目。每次我嘗試運(yùn)行該程序并單擊一個(gè)按鈕來(lái)初始化我的上傳器類(lèi)時(shí),它都會(huì)失敗并顯示一條錯(cuò)誤消息:FirebaseApp 名稱(chēng) [DEFAULT] 已經(jīng)存在!找了半天,還是沒(méi)找到有用的。我已經(jīng)嘗試過(guò) OAuth2 令牌(在 Google Cloud 中創(chuàng)建了一個(gè)服務(wù)帳戶(hù),獲得了 JSON 文件)、環(huán)境變量(不會(huì)檢測(cè)到),以及文檔中的幾乎所有內(nèi)容。 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 作為我的構(gòu)建工具。這是我到目前為止所得到的,它似乎可以很好地構(gòu)建而沒(méi)有問(wèn)題。我是否缺少任何依賴(lài)項(xiàng)? 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貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
您不能firebase-admin
與其他 Firebase Android 庫(kù)一起使用,例如firebase-auth
和firebase-firestore
。您應(yīng)該使用 Admin SDK 或 Android SDK,但絕不能同時(shí)使用兩者。
來(lái)到確切的錯(cuò)誤消息,這表明initializeApp()
在您的應(yīng)用程序中被多次調(diào)用。它正在嘗試初始化[DEFAULT]
, 當(dāng)一個(gè)已經(jīng)存在時(shí)。
添加回答
舉報(bào)
0/150
提交
取消