2

I want to get FirebaseApp from maven

in order to do:

 com.google.firebase.FirestoreOptions firestoreOptions = FirestoreOptions.Builder() .setDatabaseUrl("xxx") .setCredentials(ServiceAccountCredentials.fromStream(serviceAccount)) .build(); com.google.firebase.FirebaseApp.initializeApp(firestoreOptions); 

but I don'k know which artifact to download

I have tried with:

<dependency> <groupId>com.google.firebase</groupId> <artifactId>firebase-admin</artifactId> <version>6.13.0</version> </dependency> 

but the builder has .setDatabaseId() instead of setDatabaseUrl()

as I see in the doc: https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/FirebaseOptions.Builder#setDatabaseUrl(java.lang.String)

and the imports are

import com.google.cloud.firestore.Firestore; import com.google.cloud.firestore.FirestoreOptions; 

instead of

import com.google.firebase.Firestore; import com.google.firebase.FirestoreOptions; 
1
  • firebase have many libraries, which one you are looking exactly in another word, what you want to do exactly Commented Jun 9, 2020 at 16:22

1 Answer 1

3

It is well document in google documentation

First of all you need to import this dependency in pom.xml:

<dependency> <groupId>com.google.firebase</groupId> <artifactId>firebase-admin</artifactId> <version>6.13.0</version> </dependency> 

Or if you are using gradle :

dependencies { implementation 'com.google.firebase:firebase-admin:6.13.0' } 

And then your code should look like:

// Impots import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; // And code FirebaseOptions options = new FirebaseOptions.Builder() .setCredentials(GoogleCredentials.getApplicationDefault()) .setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/") .build(); FirebaseApp.initializeApp(options); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.