What is Firebase?
It is back-end System which stores the data of any app or may be a website, It is easy and fast to implement. You can create Real-time database, authentication,cloud messaging, even Admobs, Push Notifications etc with it.
Steps to implement Firebase in your Android App.
Go to https://firebase.google.com/ and get logged in with your gmail and click on go to console.

It will redirect you to the dashboard it will show the list of Projects that you have, and if not than you just need to create one.

Now create a project in your android studio and then again go to the browser to the firebase console and Click on Add Project, give name to your project and select your preferred location.It will redirect you to the dashboard of your Project like below.

Now select Add firebase to your android App from the dashboard as we are working for android. It will give a dialog where you need to add the project info. Follow the below steps for adding project info.
- Android package name :- This would be the name of your app's package you'll find it in the manifest in Android Studio just copy and paste it.

- App nickname (optional) :- It is optional you can provide any name it is not visible to user.
- Debug signing certificate SHA-1 (optional):- You need to add SHA 1 key that you can generate from the android studio.
- Steps to generate SHA 1
- Go to Android studio and click on gradle on the right-hand side panel, it will open a side window there and click on Refresh button it will start a build process wait until the process gets over.


- It will open a list, select the root folder of your app from it, open the Task-and than -android -double click on signingReport it will start generating a key, wait for a while.


- Inside the run panel you will get the SHA 1 key, just copy and paste it in the console and register your App.


- It will give you an google-service.json file download and paste it in the android studio in the app folder for that you need to switch over to Project View and paste it to the app folder.

- Now go to the console again hit continue and follow the rest of instructions .
- You need to add the following lines in your project in Android Studio.
- In Project-level build.gradle add the below line.
- classpath 'com.google.gms:google-services:3.1.0'
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
- In App-level build.gradle add the below line.
- apply plugin: 'com.google.gms.google-services'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
- In Project-level build.gradle add the below line.
- Go to Android studio and click on gradle on the right-hand side panel, it will open a side window there and click on Refresh button it will start a build process wait until the process gets over.
- Steps to generate SHA 1
[…] Before Going to this tutorial hope you followed the Part I for connecting firebase to android and if not than click here. […]
ReplyDelete