我一直在尝试使用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