Write a post

Enjoy this post? Give Aasheesh a like if it's helpful.

13

Firebase Tutorial: Integrate Firebase to your Android App

Published Jan 12, 2017Last updated Jan 18, 2017
Firebase Tutorial: Integrate Firebase to your Android App

Introduction

Developing a successful app is not easy. In order to reach a broad audience, app developers need to consider iOS, Android, and mobile web users. To build apps for these platforms, you would need a backend server to store data that support your apps. You also want to get your users logged in (hopefully, lots of users), which means your backend would have to scale. Then, after you solve your scaling problem, you would need to find creative ways to get more users and measure these activities on your admin dashboard. You would also have to account for the possibility that your backend server might crash abruptly. In such cases, how would you recover it and bring your app back from such crashes?

Don’t you wish all this was easier? That’s where Firebase comes in to solve all your backend database problems.

It has all the tools to develop a successful app. It helps you reach the users, keep them engaged, scale up to meet the demand in addition to getting paid. Firebase also provides test lab and crash reporting to diagnose and prevent errors in your app. Your backend infrastructure problems can be resolved with Firebase real-time database, file storage, and hosting solutions.

Acquiring new users is easy with Invites and AdWords ad Dynamic Links. Furthermore, the authentication component gets the users logged in with minimal friction. Once your app has been installed, you can keep your users engaged with push notifications, cloud messaging, and app indexing. Apart from all these features, with Remote Config, you have the freedom to experiment with app features and optimize the user experience in real time. You can even monetize using the AdMob component, which has already enabled countless developers to monetize their app.

Finally, the Analytics component, designed specifically for Firebase users, offers meaningful insights into how well these components are working for you and your users. With Firebase Analytics you can measure and optimize your AdWords campaigns, discover who your most valuable users are, and understand exactly how they are using your app.

Firebase tutorial

All these Firebase features work great independently and provide solid infrastructures to build your app on; however, they work even better when combined in creative ways.

The best way to learn Firebase is to quickly start building an app in firebase console.

Integrating Firebase App in Android app

Let’s get started with working on Firebase. We will describe how to start a project through initialization in firebase console and how to setup and use Firebase in an Android project.

Firebase tutorial

It only takes about 30 seconds to get started with Firebase and from there on, we can proceed to build an app.

So let’s get started.

We will build an app in Android to show how to integrate it with Firebase as backend.

First, create a new Android project in Android studio.

To integrate firebase into it, we will use a quick shortcut.

Go to File -> Project structure -> cloud -> check Firebase checkbox, click OK.

This will set up Firebase in our Android project.

We will now go to app Gradle file. We will find that there is a Firebase dependency in the dependency section.

compile 'com.firebase:firebase-client-android:2.3.1'

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
 	  compile 'com.android.support:appcompat-v7:24.0.0'
 	 compile 'com.firebase:firebase-client-android:2.3.1'
}

Firebase tutorial

Now, copy the package name from Manifest file of your project and open the Firebase console in your browser. Then proceed with creating a new project there. Give it a name and your Firebase project is created.

Firebase tutorial

Open up the console of firebase at https://console.firebase.google.com and create a project. Fill up the form as shown in the screenshot below.

Firebase tutorial

Once you've created a project, this is how the console of your Firebase project will look like.

Firebase tutorial

Since we are integrating Firebase in an Android app, click on “add Firebase to your Android app”, and fill in the package name in the popup window as seen below.

Firebase tutorial

Debug signing certificate is going to be required if you do dynamic links, invites, Google sign in, support OAuth, etc.

This link shows the command to generate your signing certificate in the machine terminal:
https://developers.google.com/android/guides/client-auth.

You should be able to generate this certificate, paste it in the "Package name" field, and click “add app”.

Firebase tutorial

Now, download the google-services.json config file and add it in the app folder of your android project.

Firebase tutorial

The next thing you need to do is to add Google Services classpath into your project.

Go to your project's build.gradle file and add the following line in the dependencies section:

Classpath ‘com.google.gms.google-services:3.0.0’

And then add the following line at the end of your app’s build.gradle (Module:app) file:

Apply plugin: ‘com.google.gms.google-services’

Firebase tutorial

This creates your Firebase project, which is well integrated with your Android app.

Firebase tutorial

Now that you have successfully integrated Firebase in your Android app, you can run your project in the emulator.

This way you can enhance the power of the database as a service with Firebase and start building your app, which your users would love to use.

Let Firebase handle the details of your app's backend infrastructure, user engagement, and monetization. With Firebase's help, you can spend less time worrying about the backend database and more time in building your perfect app for your loyal users.

Discover and read more posts from Aasheesh
get started
Enjoy this post?

Leave a like and comment for Aasheesh

13
Be the first to share your opinion

Subscribe to our weekly newsletter