I did an android client application using Firebase, it's working well. I want to do an admit application, but I got an issue. it looks like there are threads with the same issue, but the solution did not work for me.
I'm following the doc: https://firebase.google.com/docs/admin/setup
Then I created a brand new project (this project do not have client library and won't have). I added
compile 'com.google.firebase:firebase-admin:4.1.3'
First, I got this error
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.
After investigation, I found
Error:Conflict with dependency 'com.google.code.findbugs:jsr305'.
The solution is to add
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
It's working, but I still got some warning.
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.
I can live with that, then I continue.
I create my admin key and downloaded the file. In the doc, they ask us to do this code:
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
But I did not found where to put the file to make it work (obviously with the right folder name and file name). After some investigation, I found I can place the file in
res/raw/serviceAccountKey.json
and creating a FileInputStream like this
InputStream serviceAccount = getResources().openRawResource(R.raw.serviceAccountKey);
Perfect. Seems to work, then the code look like this
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);
For now, I don't have any error. then I do the next step
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());
}
});
But, onDataChange and onCancelled are never called. I don't see any error.
After investigation, I found others with the same issue
Firebase Admin Java SDK not doing any operation
But the solution did not work.
have Anyone an idea? Thanks