How to Add Firebase-Admin to My Android Project

How to add firebase-admin to my android project?

firebase-admin is not intended for use in Android apps. It's for accessing Firebase services from servers your control.

From the documentation regarding prequisites:

  • Make sure that you have a server app.
  • Make sure that your server runs the following depending on which Admin SDK that you use:

    • Admin Node.js SDK — Node.js 8.13.0+
    • Admin Java SDK — Java 7+ (recommend Java 8+)
    • Java 7 support is deprecated.
    • Admin Python SDK — Python 3.5+
    • Admin Go SDK — Go 1.9+
      Admin .NET SDK — .NET Framework 4.5+ or .Net Core 1.5+

The google-services plugin is giving you that warning because it thinks every maven target with group "com.google.firebase" is actually a Firebase Android client SDK, which all must be the same version in your app.

Add Firebase auth and Firebase admin in same Android Project

The Firebase Admin SDK is not intended for use in Android apps. It's for backend code running in a controlled server or desktop that you fully control. Please don't try work around this - instead your Android app should be invoking a backend that uses the Admin SDK to perform the work you need. It would be a fairly massive security hole for an app to have the Admin SDK and a service account bundled into it, as that leaves your project open to direct, easy abuse by anyone who can download your app and get the service account credentials.

How to add Firebase Admin SDK to a Google Cloud Platform and communicate with an app?

If you've never done something like this before, I'd recommend starting with callable Cloud Functions. The documentation has a nice example of how to implement these and call them from your Android code.

Inside the Cloud Function you can then use the Admin SDK to access for example Firebase Authentication. See the documentation importing the required modules for an example of how to set up the Admin SDK, and then the documentation of the Admin SDK for an example of how to get a list of users.

Firebase Admin SDK for Android, methods not found

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.



Related Topics



Leave a reply



Submit