Firebase Connection

Papon Ahasan
3 min readFeb 7, 2023

Prerequisites

  • Install or update [Help > Check for Update] Android Studio to its latest version
  • Make sure that your project meets these requirements:

01) Targets API level 19 (KitKat) or higher [Gradle Scripts > build.gradle(app) > android.defaultConfig { minSdk 23 }]

02) Uses Android 4.4 or higher [Gradle Scripts > gradle-wrapper.properties > distributionUrl=.../gradle-7.5-bin.zip]

03) Uses Jetpack (AndroidX) [Gradle Scripts > gradle.properties > android.useAndroidX=true & Gradle Scripts > build.gradle(app) > android{compileSdk 33}]

04) Set up a physical device or use an emulator( Google Play services require or emulator have Google Play services installed) to run your app.

05) Sign into Firebase using your Google account.

Connect your Android app to Firebase using one of the following options:

  • Option 1: Adding your app to the Firebase console(recommended)
  • Option 2: Installing the SD

Option 1: Adding your app to Firebase console

  • Visit firebase console
  • Click [Add project > Continue.. > Choose or create a Google Analytics account > Continue..]
  • Click the Android icon (plat_android) or Add an app to launch the setup
  • Enter your app’s package name[A package name uniquely identifies your app on the device and in the Google Play Store] in the Android package name field [app > java > MainActivity > "com.example..."]. or go to application ID [build.gradle > android { defaultConfig {applicationId "com.example..."}}]

Get the SHA-1 fingerprint certificate for debug mode: https://www.youtube.com/watch?v=9DKiyRLd1HA&ab_channel=AlexMamo

  • Download (google-services.json) file. Then move the root directory(Project) of your app and paste the file.
  • To make the google-services.json config values accessible to Firebase SDKs, you need add the Google services Gradle plug-in to your project-level: build.gradle.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
}

Note : only buildscript {}, pluginManagement {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed.

  • Then, in your module (app-level) build.gradle file, add both the google-services plug-in]
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}

dependencies {
implementation platform('com.google.firebase:firebase-bom:31.2.0')

// When using the BoM, don't specify versions in Firebase dependencies
implementation 'com.google.firebase:firebase-analytics-ktx'
}

After adding the plug-in and the desired SDKs, sync your Android project with the Gradle files.

  • Check Result

--

--