我使用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.
经过调查,我找到了
Error:Conflict with dependency '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 not doing any operation
但解决方案不起作用。
有人有想法吗?感谢
答案 0 :(得分:0)
我通常在c ++工作,java / gradle / android对我来说是全新的。我不知道“gradle”不仅仅是Android studio中的文件。
然后,如果你像我一样,并且你是android / firebase / java中的新手,并且犯了与我相同的错误,那么就可以使它工作。
为Java EE开发人员安装的Eclipse IDE https://eclipse.org/downloads/eclipse-packages/
为eclipse添加Gradle支持 http://www.vogella.com/tutorials/EclipseGradle/article.html
创建一个新项目。 (使用Eclipse教程)
从firebase教程重做firebase的firebase教程
现在我终于在onDataChange中找到了断点,数据似乎正确