![Koda School](/_next/image?url=%2Fimages%2Flogo.png&w=96&q=75)
KodaSchool
Learn To Code
Integrating Firebase with Android
This tutorial outlines the process of integrating Firebase to an android application by manual Firebase configuration or through the usage of Firebase assistant in Android Studio.
topics
Introduction
Firebase is a feature-rich platform developed by Google for creating and expanding online and mobile applications. It offers a range of resources, including real-time databases, cloud storage, authentication, and hosting, to assist developers in producing high-quality programs.
Firebase attempts to make backend development less complicated so that developers may concentrate more on the main features and user experience of their applications. Developers may effectively manage application data, optimize application speeds, and raise user engagement by utilizing Firebase's products.
Firebase's Realtime Database, which enables real-time data synchronization and storage across users, is one of its most notable features. This NoSQL cloud database enables offline functionality, so information is accessible even when the user is not online. It also automatically synchronizes upon reestablishing connectivity. This is very helpful for developing collaborative Android applications such as chat apps, real-time gaming, or any other application that needs to use the most recent data across several devices.
Additionally, Firebase provides strong authentication options, which facilitate the management of user identification and security for developers. Developers may quickly integrate sign-in procedures using several providers, such as phone number, email address and password, and third-party providers like Google, Facebook, and Twitter, with Firebase Authentication. This guarantees that user data is safe and authentication runs smoothly by lowering the overhead involved in creating secure authentication systems from scratch.
This tutorial offers a step by step procedure on how to integrate Firebase to Android applications in two ways.The first option is integrating using Firebase Console while the second option is done using the Android Studio Firebase Assistant.
Prerequisites
- Ensure the latest Android studio installed
- Ensure that an android device is setup and connected.Optionally,use an emulator
Option 1:Integration using Firebase Console
Step 1:Create a project in the Firebase console
- Enter the project name of your choice and check the boxes to accept the terms and why you want to use Firebase services then click continue.In this example name your project ImageUpload.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F42325fa957a100d8a2aa76051633c22a7f58e0da-975x538.png%3Fw%3D975%26auto%3Dformat&w=3840&q=75)
- Enable Google Analytics in your Firebase project to allow you to get real time data analytics about your application in the Firebase Google Analytics Console.This choice is optional.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F36cdb13afe99dc73f14ee337a712eab588dd8a8f-878x540.png%3Fw%3D878%26auto%3Dformat&w=3840&q=75)
- Next, choose location then accept Google Analytics terms and click Create project.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Fd7dac9caad0ade30f04dbc0cb5d259d363ddab69-940x566.png%3Fw%3D940%26auto%3Dformat&w=3840&q=75)
- The project will take less than a minute to provision resources and be ready for use.After the setup process is complete,click continue to start exploring the created project.
Step 2:Adding Android App to Firebase Project
- Create an Android application in Kotlin and name it ImageUploader.Once the project is completely configured note down the package name within the MainActivity.kt class.In this the app the package name is com.example.imageuploader.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F85535da7b97fa3374c275a9c0c3a4f151e5f4466-1296x669.png%3Fw%3D1296%26auto%3Dformat&w=3840&q=75)
- Under the project overview,click the android icon to navigate to the next step.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F8eddf9aa1e89ff63296af7cb4e2074735ffc362f-1330x580.png%3Fw%3D1330%26auto%3Dformat&w=3840&q=75)
- Enter the Android package name,app nick name and Debug signing certificate SHA-1(Optional) and click Register app.
- To generate Debug signing certificate use this this command for Mac or Linux keytool -list -v \-alias androiddebugkey -keystore ~/.android/debug.keystore and keytool -list -v \-aliasandroiddebugkey-keystore%USERPROFILE%\.android\debug.keystore for windows users.
After entering the command in Android Studio terminal you will be prompted to enter a password.The password is android.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F64e4a956363fbbfe8c9669d22f5f22123620d206-946x393.png%3Fw%3D946%26auto%3Dformat&w=3840&q=75)
Step 3:Entering android package,nickname and SHA-1
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Fb9fe209dd00fd1a1dfce71f8682c40cc9f82eba4-846x550.png%3Fw%3D846%26auto%3Dformat&w=3840&q=75)
- Download google-services.json file that will be added to the android app-level root directory then click next.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F83603179f9e73c69af439671a27533c4b46b2c1e-946x554.png%3Fw%3D946%26auto%3Dformat&w=3840&q=75)
Contents of google-services.json file
{
"project_info": {
"project_number": "860662134691",
"project_id": "imageupload-eb8fa",
"storage_bucket": "imageupload-eb8fa.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:860662134691:android:adc8d890400b745f33cc16",
"android_client_info": {
"package_name": "com.example.imageuploader"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyAxrC03-5tVQMaSiuVpt5nDzoXsU5eeB7c"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
Google-services.json in android app
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F838ba29932f5ee4f10c725eaca4c7664b663eea4-1319x586.png%3Fw%3D1319%26auto%3Dformat&w=3840&q=75)
Project level Build.gradle.kts configuration
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Fb3e427824613ff0e0441042ae87ab11cec67d1a0-1274x548.png%3Fw%3D1274%26auto%3Dformat&w=3840&q=75)
App level Build.gradle configuration
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Fae91e4be267c5b2d8bdea2c9c8d6f45e3ef4451a-1269x550.png%3Fw%3D1269%26auto%3Dformat&w=3840&q=75)
- The next step guides you on how to include the essential dependencies in the build.gradle file.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Fb46b7026966ff823d8782d35c98aac53af3a2629-923x575.png%3Fw%3D923%26auto%3Dformat&w=3840&q=75)
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Ff3b68854d66e1d45278a88c7a989f71a55d21214-866x385.png%3Fw%3D866%26auto%3Dformat&w=3840&q=75)
- Clicking next navigates you to the page where you will be required to go to the console.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Fbe7eafc28e83d71135c66b97c82e1a8569621de2-984x605.png%3Fw%3D984%26auto%3Dformat&w=3840&q=75)
- After all the setup is complete,this will be the final appearance in the Firebase Console.
Option 2:Integration using Firebase Assistant
Step 1:Configure Android Studio with Latest Update
- To use Firebase Assistant ensure that you are using the latest Android Studio.If you are using previous versions,you can go to Help and choose check updates(Linux/Windows) while for MacOS go to Android Studio then check updates.
Step 2:Select Firebase Products
- Next go to Tools then select Firebase.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F45f102351f6d1f44ce31e07658d6effab25435d1-1188x596.png%3Fw%3D1188%26auto%3Dformat&w=3840&q=75)
Step 3:Choose Google Analytics
- Next select Firebase products such as Analytics.Click Get started with Analytics then select Connect to Firebase.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Ff467a3b7a5b804bbd31407bf906d57410618bfbb-1287x633.png%3Fw%3D1287%26auto%3Dformat&w=3840&q=75)
- Firebase assistant will navigate to the Firebase Console.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Ffbad90502a9b628aef3fbc7693b928e359dd98cb-847x560.png%3Fw%3D847%26auto%3Dformat&w=3840&q=75)
- Follow the next steps similar to the way we configured Firebase in the First option.
- Add the Analytics selection to your app.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F4eaf43584a43edfd141fead0ea532d09e9dcb2ba-1220x631.png%3Fw%3D1220%26auto%3Dformat&w=3840&q=75)
- Next,after moving through all the steps as guided by the Firebase Assistant,the app will automatically be linked to Firebase.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2F54a6c4682234e6552e1d7d9d0e349513dd5e7ecc-1326x660.png%3Fw%3D1326%26auto%3Dformat&w=3840&q=75)
- Finally,if all the steps outlined by the Firebase assistant you will end up with a complete integration as shown below.
![Image](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fbu96b58t%2Fproduction%2Fa9f7f3d943534b978c2a9b9f70d779ca9bb5a9ed-1316x589.png%3Fw%3D1316%26auto%3Dformat&w=3840&q=75)
Conclusion
The integration of Firebase to an Android application does not need to be complicated when you follow the steps outlined by the Firebase Assistant.Additionally, the option of creating a project in the Firebase manually is very seamless and straightforward and will let you set up a backend for your web and mobile applications within a very short time.
share
Android Expert developing mobile applications with 4+ Years of Experience.