3

Code for Initialising Firebase-Admin SDK in Android

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_excel);

    FileInputStream serviceAccount = null;
    try {
        serviceAccount = new FileInputStream("android.resource://com.app.hello/raw/hello.json");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    FirebaseOptions options = null;
    try {
        options = new FirebaseOptions.Builder()
                .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                .setDatabaseUrl("https://hello.firebaseio.com/")
                .build();
    } catch (IOException e) {
        e.printStackTrace();
    }

    FirebaseApp.initializeApp(options);



}

Error while building the app for run:

error: cannot find symbol
                .setCredentials(GoogleCredentials.fromStream(serviceAccount)

error: incompatible types: FirebaseOptions cannot be converted to Context FirebaseApp.initializeApp(options);

group work
  • 33
  • 7

1 Answers1

0

Admin SDK cannot and should not be used on Android. It is for server-side and other back-end environments only.

Hiranya Jayathilaka
  • 7,180
  • 1
  • 23
  • 34