Mobile applications need a back-end server in order to perform tasks such as authenticating users and synchronizing user data across multiple devices. Creating such a server, however, requires a skill set that most independent app developers lack. Fortunately, there are several back-end as a service platforms, often called BaaS, you can use today. Google's Firebase is one such platform.
Firebase offers essential services such as analytics, crash reporting, user authentication, and cloud messaging at no cost. Its freemium services include a real-time NoSQL database, file hosting, and static website hosting.
In this tutorial, I'll show you how to add user authentication, analytics, and remote data storage to your Android app using Firebase.
To follow along, you'll need:
Android Studio 2.2 RC2 or higher
1. Using Firebase Analytics
Firebase Analytics is one of the most popular mobile app analytics solutions available today. By using it, you can get a precise understanding of who your users are and how they are using your app.
Step 1: Set Up Firebase Analytics
The latest canary builds of Android Studio have built-in support for Firebase Analytics. That means you can add Firebase Analytics to your project without ever having to leave Android Studio.
To start integrating Firebase Analytics with your project, click on Tools > Firebase . You will be presented with the following Assistant window:
Click on Analytics and then Log an Analytics event .
You must now associate your Android Studio project with a Firebase project. Therefore, click on the Connect to Firebase button.
In the dialog that pops up, you will be able to see all your existing Firebase projects. You can either pick one of them or choose to create a new project. For now, I suggest that you choose the Create new Firebase project option, and give a unique name to the project.
Once you press the Connect to Firebase button that's inside the dialog, Android Studio will automatically make all the required configuration changes, such as generating a google-services.json file and uploading a SHA1 fingerprint.
You can now press the Add Analytics to your app button to add the Firebase plugin and the Firebase Core dependency to your project. Android Studio will show you the exact changes that will be made to the build.gradle files.