Add Firebase to your Android Project — Devstringx
Brief Description of Firebase
- Firebase may be a mobile platform that helps the user quickly develop quality apps.
- It’s used for developing a new mobile app and implementing an existing app with new functionality to attract the audience.
- It also provides a Realtime database which is a NoSQL database that store data and sync data.
- We will also add Authentication Functionality in our android project using Firebase, it has various Sign-in methods like Google, Facebook, Twitter, etc.
All the Sign-in methods are shown below:
Add Firebase to Your Android Project
- – First, you have to install or Update Your Android Studio to its latest version.
- – Your project must meet these requirements:
- – Minimum SDK: API 20 (KitKat Wear) or higher.
- – Use Android 4.4W or higher.
- – Use a real device or use an in-built emulator, according to your system configuration.
- – Sign in to Firebase with an existing Google account or create a new one.
Options to Add Your Android Project With Firebase
There are two options for your android project with firebase:
- Using the Firebase Setup
- Using the Android Studio Firebase Assistant (requires additional configuration)
Option 1: Using the Firebase Setup
1. Create a Firebase Project:
- – Open Firebase Console, Sign in with your account and click on add(+) project
- – If you have an existing Google cloud, enter its name or select it from the dropdown
- – For creating a new project, Enter its name
- – Select the Firebase terms and conditions and click on Continue
- – Enable Google Analytics, which offers the optimal experience of firebase products
- – Click on Add Firebase or create a project
2. Add Your App to Firebase:
- Visit Firebase Console, Click on your added project
- Click on the android icon to register the app
- Enter the package name of the project
- Enter App nickname or Debug signing certificate SHA-1(optional)
- Click on the Register app
3. Add Config file to Your Android Project:
- – Download (google-services.json)
- – Add JSON file into your android app root directory
- Make sure that, you have the Google Maven repository in your (Gradle) at the project level.
- In (app-level) Gradle file, apply the Google Services plugin:
apply plugin: ‘com.google.gms.google-services
4. Add Dependencies Into (app-level) Gradle file
// Add Firebase BoM dependency
// Dependency for Google Analytics
5. Sync your app to download the dependency that you have added.
6. If you are facing any issues throughout the setup, go to Android Troubleshoot
Option2: Using the Android Studio Firebase Assistant
The Firebase Assistant adds the necessary plugins, files, and dependencies to your project.
- Open your Android Studio and select the project which you want to add to the firebase
- Select Tools > Firebase
- In the Assistant panel, Choose the firebase product to add to your app:
- Click on Connect to Firebase to connect your android app with firebase.
- Click on the desired product which you want to add to your project (Ex: Add Google Analytics).
- Now, sync your app to download all the dependencies in your project.
- You can also add various firebase products to your project, according to the requirements.
4. You can add various firebase products like:
- – Add Firebase Authentication.
- – Add Firebase Messaging Services.
- – You can store data in the cloud or in a real-time database.
- – By Crashlytics, You can find when and why your app crashes.
5. That’s it, Your app is successfully connected to the firebase.
6. If you are facing any issues throughout the setup, go to Android Troubleshoot.
Originally published at https://www.devstringx.com on July 26, 2022