Tag: Kotlin

Firebase Authentication for your Android App – Part 1

This part simply explains step by step process of integrating Firebase to your brand new Android app from scratch in order to help utilize various BE solutions that Firebase provides – Database, User Authentication, Analytics, Hosting etc.

  • Project requirements:
    • Target API Level 16+
    • Gradle 4.1+
    • AndroidX Jetpack Library
  • Sign into https://console.firebase.google.com/ with your desired google account.
  • Create a new Firebase Project.

(Note: I decided to create this sample project without Google Analytics enabled for simplicity.)

  • Once the Firebase project is created , it’s time to register your Android app to the firebase. Click on the Android icon in the middle
  • Enter your app’s package name in the field Android Package Name. ( If you are unsure of how to determine your app’s package name – check the AndroidManifest.xml file for package= & copy the text that follows of the format com.xx.yy ) and click on Register App.
  • Download the google-services.json file & move it to the app module directory of your Android project.
  • Open the Project level gradle file Project:<project_name> build.gradle and add the following code:
buildscript {
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
  }
  dependencies {
    ...
    // Add this line
    classpath 'com.google.gms:google-services:4.3.4'
  }
}

allprojects {
  ...
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
    ...
  }
}
  • Open the app build.gradle and add the following code:
apply plugin: 'com.android.application'
// Add this line
apply plugin: 'com.google.gms.google-services'

dependencies {
  // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:26.3.0')

  // Add the dependencies for the desired Firebase products  // For Authentication, add the following
  implementation 'com.google.firebase:firebase-auth-ktx'}

Note: Firebase Android BoM stands for Bill of Materials – which basically lets you specify one single version and imports all Firebase Libraries specified as dependencies compatible with that version, hence you don’t need to individually import these libraries for a specific version.

  • Remember to click on Sync now, to ensure all the dependencies are added to the project as necessary.

The above steps concludes what needs to be done to integrate Firebase to your Android app. In upcoming part 2, I will demonstrate how to enable firebase authentication for providing the simple sign up/ sign in functionality for your users.