我一直在嘗試使用Firebase,並且嘗試設置服務器時遇到問題。使用Firebase缺少.setServiceAccount方法
雖然下面的文檔我偶然發現了這一點的代碼。
FirebaseOptions options = new FirebaseOptions.Builder()
.setServiceAccount(new FileInputStream("path/to/ serviceAccountCredentials.json"))
.setDatabaseUrl("https://databaseName.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
我的問題是,它似乎不支持setServiceAccount方法,因爲我得到一個錯誤的IDE通知我的方法是錯誤的。去看Firebase文檔,似乎沒有一個名爲.setServiceAccount的方法。 initializeApp方法會出現類似的問題,如果參數選項似乎有錯誤。
這裏似乎有類似的話題。 Compile time error for setServiceAccount() with FirebaseOptions.Builder()
但用戶的一個建議,以除去 編譯 'com.google.firebase:火力-服務器SDK:[3.0.0,)' 從build.grade 命令。不幸的是,對我來說問題依然存在。可能是什麼問題呢?
我的build.gradle看起來是這樣的:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.google.firebase:firebase-messaging:9.0.1'
compile 'com.google.firebase:firebase-core:9.0.1'
compile 'com.google.firebase:firebase-storage:9.0.1'
compile 'com.google.firebase:firebase-server-sdk:[3.0.0,)'
compile 'com.google.android.gms:play-services-appindexing:9.0.1'
}
謝謝你的迴應。不幸的是,這個問題仍然存在。我最近刪除了建議的項目,並留下了編譯'com.google.android.gms:play-services-appindexing:9.0.1' compile'com.google.firebase:firebase-server-sdk:[3.0.0, )' – Czar
您是否嘗試運行gradle sync,或者只是編譯(通過該行註釋)以幫助IDE更新其緩存? –
是的,我點擊與這兩行同步。我不明白你什麼時候說「編譯(用那行評論)」。從外觀上看,似乎不再支持setServiceAccount,因爲我沒有在Firebase文檔中看到它:https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseOptions.Builder #public-constructor-summary – Czar