How to add firebase in Android (Java/Kotlin)
Please Subscribe Youtube| Like Facebook | Follow Twitter
Introduction
In this article we will learn how to connect firebase in android project/app. Follow below steps to setup:
1) Create Firebase Project
- Write project name
- Enable Google Analytics
- Configure Google Analytic
2) Connect your Android project/app to Firebase Project.
- Register App
- Download Configuration File
- Add Firebase SDK
- Run your app to verify installation
1) Create Firebase Project
First create or sign-in google account and then go to firebase console and click on create a project.
![](https://programtown.com/wp-content/uploads/2020/05/1-1024x495.png)
a) Write project name
![](https://programtown.com/wp-content/uploads/2020/05/2-1024x773.png)
b) Enable Google Analytics
![](https://programtown.com/wp-content/uploads/2020/05/3.png)
c) Configure Google Analytic
![](https://programtown.com/wp-content/uploads/2020/05/4.png)
![](https://programtown.com/wp-content/uploads/2020/05/5.png)
2) Connect your Android project/app to Firebase Project
Now After creating project on firebase connect your android app to it.
![](https://programtown.com/wp-content/uploads/2020/05/6.png)
a) Register App
Add your android project package name and project name and click on register app
![](https://programtown.com/wp-content/uploads/2020/05/77.png)
b) Download Configuration File
Download google-services.json config file and add it to you android app/project. Switch to the Project view in Android Studio to see your project root directory. Move the google-services.json file that you just downloaded into your Android app module root directory.
![](https://programtown.com/wp-content/uploads/2020/05/8.png)
![](https://programtown.com/wp-content/uploads/2020/05/9-1.png)
c) Add firebase SDK
Now at Project-level build.gradle of your android app/project add google() at repositories (if not present) and classpath ‘com.google.gms:google-services:4.3.3’ at dependencies block.
![](https://programtown.com/wp-content/uploads/2020/05/10.1.png)
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.3'
}
}
allprojects {
...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
...
}
}
And at App-level build.gradle add apply plugin: ‘com.google.gms.google-services’ and implementation ‘com.google.firebase:firebase-analytics:17.4.1’
![](https://programtown.com/wp-content/uploads/2020/05/11.1-1.png)
apply plugin: 'com.android.application'
// Add this line
apply plugin: 'com.google.gms.google-services'
dependencies {
// add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics:17.4.1'
// add SDKs for any other desired Firebase products
// https://firebase.google.com/docs/android/setup#available-libraries
}
d) Run your app to verify installation
Then finally sync and run your android project. You may need to uninstall and reinstall your app and keep your internet connection active.
![](https://programtown.com/wp-content/uploads/2020/05/13.png)
![](https://programtown.com/wp-content/uploads/2020/05/14.png)
Conclusion
So in this article we have learned how to add firebase to android project.
Please Subscribe Youtube| Like Facebook | Follow Twitter