Firebase Admin SDK not initializing(Java)

1.4k views Asked by At

I am quite new to Java and I am currently trying to use the Firebase Admin SDK with my application.
I am using Eclipse with the Maven plugin.

I have included this dependency in my Maven pom.xml file

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

After that, I made a new application under src/main/java and I tried to initialize the SDK with the code below, as the official Google Document asked me to.

package com.vogella.maven.quickstart;

import com.google.firebase.FirebaseOptions;

public class App  {

    public static void main( String[] args )
    {
       /*Firebase SDKをinitializeするために*/
      FirebaseOptions options = new FirebaseOptions.Builder();
    } }

However, I am getting an error saying that I have to change the code to

Builder options = new FirebaseOptions.Builder()

Is the Google official document wrong?

1

There are 1 answers

1
OneCricketeer On BEST ANSWER

Looks like you didn't copy the rest of the code

 FirebaseOptions options = new FirebaseOptions.Builder()
  .setServiceAccount(new FileInputStream("path/to/serviceAccountKey.json"))
  .setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
  .build();

FirebaseApp.initializeApp(options);

Your error is that obviously a FirebaseOptions class cannot be assigned to a new FirebaseOptions.Builder().

You must build() the Builder