我使用 Firebase 做了一个 android 客户端应用程序,它运行良好。我想做一个录取申请,但我遇到了一个问题。看起来有相同问题的线程,但该解决方案对我不起作用。
我正在关注文档:https ://firebase.google.com/docs/admin/setup
然后我创建了一个全新的项目(这个项目没有客户端库,也不会有)。我添加了
compile 'com.google.firebase:firebase-admin:4.1.3'
首先,我得到了这个错误
Error:Conflict with dependency 'com.google.code.findbugs:jsr305' in project ':app'. Resolved versions for app (1.3.9) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
经过调查,我发现
错误:与依赖项 'com.google.code.findbugs:jsr305' 冲突。
解决方案是添加
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
它正在工作,但我仍然收到一些警告。
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160212 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160212 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160212 is ignored for release as it may be conflicting with the internal version provided by Android.
我可以忍受,然后我继续。
我创建了我的管理员密钥并下载了文件。在文档中,他们要求我们执行以下代码:
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
但是我没有找到将文件放在哪里使其工作(显然使用正确的文件夹名和文件名)。经过一番调查,我发现我可以将文件放入
res/raw/serviceAccountKey.json
并像这样创建一个 FileInputStream
InputStream serviceAccount = getResources().openRawResource(R.raw.serviceAccountKey);
完美的。似乎工作,然后代码看起来像这样
InputStream serviceAccount = getResources().openRawResource(R.raw.serviceAccountKey);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl("https://" + m_databaseName + ".firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
目前,我没有任何错误。然后我做下一步
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.println("The read succeed");
}
@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
但是,永远不会调用 onDataChange 和 onCancelled。我没有看到任何错误。
经过调查,我发现其他人也有同样的问题
Firebase Admin Java SDK 不做任何操作
但解决方案没有奏效。
有任何想法吗?谢谢