I'm building an Android app backed by a Firebase app, and I would like to be able to create an Admin account that can edit or delete other user accounts. If I'm understanding correctly, the Firebase Admin SDK should allow me to do this. So I followed the instructions here.
To set up the Admin SDK in my app. I added the following to build.app:
compile 'com.google.firebase:firebase-admin:4.1.1'
And in my Application class, I added this:
FileInputStream serviceAccount = null;
try {
serviceAccount = new FileInputStream("app/<MY-DATABASE>.json");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (serviceAccount != null) {
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl("https://<MY-APP>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
}
However, it's telling me that:
According to the docs, FirebaseOptions.Builder.setCredential()
is a new method, which replaces the deprecated FirebaseOptions.Builder.setServiceAccount()
. But setServiceAccount()
doesn't exist either.
What's going on here?
You can't use the Firebase Admin SDK in an Android app alongside the Firebase Android client libraries. The SDKs both provide classes with the exact same package and class name, so it wouldn't possibly be able to use them both at the same time (how would the compiler know which one you intend to build into your app?).
As an example, take a look at the javadoc for FirebaseOptions Builder in the Android client library:
com.google.firebase.FirebaseOptions.Builder
Now look at the same class from the java Admin SDK (note the URL is different):
com.google.firebase.FirebaseOptions.Builder
You can see for yourself that they're different things, even though they have the same name. Your compiler is therefore looking at the Android SDK definition and not the admin SDK definition.
As Frank said, you probably don't want to use the Admin library within your Android app. If you want to use the admin SDK, use it from a server you control, and have your Android app communicate with that if needed.