Passer au contenu

Firebase Google Login on Android

This guide will help you integrate Google Sign-In with Firebase Authentication on Android. I assume you have already completed the general Firebase Google setup

  1. Go to your project overview over at console.cloud.google.com

    Firebase Project Overview
  2. Click on the Add app button

    Firebase Add App Button Firebase Add App Button
  3. Select Android

    Firebase Add App Android Button
  4. Fill the first part of the form

    1. Fill the Android package name
      1. Open Android Studio at your app using npx cap open android
      2. At the very bottom of the navigator, find the Gradle Scripts Gradle Scripts section in Android Studio project navigator
      3. Find build.gradle for the module app build.gradle (Module: app) file in Gradle Scripts section
      4. Copy the android.defaultConfig.applicationId. This will be your package name in the Firebase console Build.gradle file showing applicationId configuration
      1. Paste it in the Firebase console Firebase Add App Android Package Name Field
    2. Click on the Register app button Firebase Add App Android Register Button
  5. Skip the Download and then add config file step

    Firebase Add App Android Skip 'Download and then add config file'
  6. Skip the Add firebase SDK step

    Firebase Add App Android Skip 'Add firebase SDK'
  7. Click on the Continue to console button

    Firebase Add App Android Continue to Console Button
  8. If you do not get automatically authenticated, go to settings -> general -> your apps -> find your android app and click on it

    Firebase Add App Android Settings General Your Apps Button
  9. Get your SHA1 fingerprint

    Follow steps 10-11 from the Google Login Android setup guide:

    1. Now, open the terminal. Make sure that you are in the android folder of your app and run ./gradlew signInReport

      Terminal showing gradlew signInReport command
    2. Scroll to the top of this command. You should see the following. Copy the SHA1.

      Terminal output showing SHA1 certificate fingerprint
  10. Add the SHA1 to the Firebase project

    1. Click on the Add fingerprint button Firebase Add App Android Add Fingerprint Button
    2. Paste the SHA1 you copied in the previous step Firebase Add App Android Add Fingerprint SHA1 Field
    3. Click on the Save button Firebase Add App Android Add Fingerprint Save Button
  11. Get your web client ID

    1. Go to Build -> Authentication Firebase Authentication Menu
    2. Click on the Sign-in method button Firebase Authentication Sign-in Method Button
    3. Click on the Google provider Firebase Authentication Sign-in Method Google Provider
    4. Click on the Web SDK configuration button Firebase Authentication Sign-in Method Web SDK Configuration Button
    5. Copy the Web client ID. This will be your webClientId in the initialize method of the plugin.
    Firebase Authentication Sign-in Method Web SDK Configuration Web Client ID
  12. Use the web client ID in JS.

At this point, you are TECHNICALLY ready to use Google Sign-In with Firebase Authentication on Android. However, I would recommend double-checking the setup in the Google Cloud console as explained in the next step.

Double-check the setup in Google Cloud console

Section titled “Double-check the setup in Google Cloud console”

In order to make sure that the setup is correct, you should double-check the setup in the Google Cloud console.

  1. Go to console.cloud.google.com

  2. Find your project

    1. Click on the project selector Google Cloud Console Project Selector
    2. Search up your project by the exact name of your Firebase project and click on it. In my case, it is sociallogin-tutorial-app. Firebase Project Selector Project
  3. Open the search bar and open credentials

    1. Open the search bar Google Cloud Console Search Bar
    2. Search for credentials and click on the APIs and Services one (number 2 on the screenshot) Google Cloud Console Credentials Search
  4. Verify that you see both the Android and Web client IDs in the list.

    Google Cloud Console Credentials List
  5. Verify that the Android client ID is correctly configured in the Firebase console.

    1. Click on the Android app Google Cloud Console Android App Select
    2. Confirm that the SHA1 hash is correctly configured and that it matches the one you copied in the previous steps. Google Cloud Console Android App SHA1 Configured
  6. Verify that the Web client ID is correctly configured in the Firebase console.

    1. Click on the Web app Google Cloud Console Web App Select
    2. Confirm that the client ID matches the one you copied in the previous steps. Google Cloud Console Web App Client ID Configured

Voila! You are now ready to use Google Sign-In with Firebase Authentication on Android.

If authentication hangs or fails:

  • Verify the idToken audience matches your Firebase web client ID
  • Check that Google Sign-In is enabled in Firebase Console
  • Ensure the SHA-1 fingerprint is correctly configured
  • Review the example app code for reference