Firebase Admin SDK 5.0.0, setCredentials cannot resolve ** Java ** method
This is done through a servlet module using Android Studio 2.3.2
private FirebaseApp app = null; // To avoid NullPointerExeception
private FirebaseDatabase database = FirebaseDatabase.getInstance(); // the error points here: FirebaseApp with name [DEFAULT] doesn't exist.
private DatabaseReference myRef = database.getReference("table/ID"); //Table from Firebase
It's inside the Get method, and I only want to read the value (plain). My problem is with setCredential, it just says "cannot resolve method"
I ended up in the backend gradle file:
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.34'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.53'
compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.firebase:firebase-server-sdk:3.0.3'
compile 'com.google.firebase:firebase-admin:5.0.0'
I tried a few different ways to implement the credentials, as you can see that they are "// commented out" .
Only one of them works with SDK 4+ admin "setServiceAccount" is deprecated today if I compile and deploy it to App Engine and then Firebase wants to read a table that says: java.lang.IllegalStateException: FirebaseApp named [DEFAULT] not exist.
So, I have two options ( I am open to hear everything from you ):
- setCredentials doesn't work.
-
setServiceAccount compiles but doesn't work
InputStream serviceAccount = this.getClass().getResourceAsStream("/WEB-INF/YourJsonFile.json"); //JsonFile from Account Services FirebaseOptions options = new FirebaseOptions.Builder() .setCredential(FirebaseCredentials.fromCertificate(serviceAccount)) // example (doesn't compile) //.setCredential(FirebaseCredentials.applicationDefault()) //same problem (doesn't compile) //.setServiceAccount(serviceAccount) //compiling & it throws the error: FirebaseApp with name [DEFAULT] doesn't exist. .setDatabaseUrl("https://YourDatabaseName.firebaseio.com") .build(); this.app = FirebaseApp.initializeApp(options);
And I call myRef to read a value like this:
myRef.addListenerForSingleValueEvent(new ValueEventListener() {
When I run the app it tells me the line FirebaseDatabase.getInstance (by attributes)
thank
source to share
No one has answered this question yet
Check out similar questions: