How to connect Firebase to an Android app (Part 2)


In this blog, we will see the steps for connecting Firebase as a backend to an Android application.
There are two ways of connecting Firebase to the Android application:
1 - Using the Firebase console
2 - Using Android Studio's Firebase Assistant
In my previous blog, I have explained the way 1 (i.e) by using the Firebase Console.
In this blog, we will see connecting Firebase through Android Studio's Firebase Assistant.
Steps for connecting Firebase to an Android Application
1. Open your Android Application
2. Sign in with your mail id in your Android Studio
3. Goto Tools -> Firebase, to open your Firebase Assistant
4. Choose and click any Firebase Products for your Android Project. Here, I'm choosing Realtime Database as my Firebase Product. Click "Save and Retrieve data"
5. Click "Connect to Firebase" 
6.  Enter "Firebase Project Name" and Choose "Location" and click "Connect to Firebase"
You can see the Message indicating that your app is connecting to Firebase.
7. Finally, your Android Application is connected to the Firebase
8. Go to your Firebase Console, you can see the Firebase Project you have just Created.
9. Click "Choose data sharing settings" to enable Google Assistant for your Firebase Project
Check the required checkbox and Accept the terms and conditions and click "Finish" 
9. Click "Add the Realtime Database to your app".
Then click "Accept Changes".
This will automatically make changes to your Project-level and app-level gradle files (i.e) here, the Google build script dependency to your project-level gradle file, and Google plugin and  Firebase product dependency (here Realtime Database dependency) to your app-level gradle file will be added automatically.
Your Gradle will automatically start syncing the changed dependencies. 
Changes in App level gradle file
Changes in Project-level gradle file 
10. Check that the added dependencies version is up-to-date and Google's Maven Repository is there is your Project level gradle file. At this time I'm writing this blog, the latest version of
Google buildscript dependency => ''
Realtime Database Dependency => ''
Google's Maven Repository
  1. buildscript {        
  2. repositories {      
  4.       google()  // Google's Maven repository    
  6.   }        
  7. dependencies {             
  8. classpath ''// Google Services plugin    
  9. }      
  10. }      
  11. allprojects {      
  12. // ...      
  13. repositories {    
  15.       google()  // Google's Maven repository    
  17. // ...      
  18. }      
  19. }      
11. Update the added dependency versions to the latest versions and again sync the project.
Also, the "google-services.json" file will also be added automatically. Goto Project->app to check that the file is added.
12. Run your app to send verification to Firebase that you have successfully integrated Firebase to your app. 
You will receive a "FirebaseApp initialization successful" message in the Logcat.
Congrats, you have successfully connected Firebase to your Android Application. Comment below if you have any doubts regarding this topic.