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.
a) Write project name
b) Enable Google Analytics
c) Configure Google Analytic
2) Connect your Android project/app to Firebase Project
Now After creating project on firebase connect your android app to it.
a) Register App
Add your android project package name and project name and click on register app
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.
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.
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’
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.
Conclusion
So in this article we have learned how to add firebase to android project.
Please Subscribe Youtube| Like Facebook | Follow Twitter