Let’s get start with Firebase & Android — 01

Pium Sudhara
5 min readAug 9, 2020

--

Firebase Tutorial 01

Hello everyone, hope you guys doing very well. In this article we’re going to build an simple android application with Firebase as the backend service. Check my previous article about Firebase in below link.

I am intending to make this into an episode based tutorial so i will add other parts like Firebase Firestore, Firebase Cloud Storage and Push Notifications. In this project we are going to use Firebase Authentication and sign up new user and login.

Let’s get started.

Prerequisites

You need following things to do this tutorial :

Project Setup

  • Android Setup

If your don’t have install the Android Studio, you can download and install the setup using this link, https://developer.android.com/studio . After the installation you need to create an New Android Project or you can download sample project using this repository https://github.com/piumsudhara/SimpleAndroidApp.

Create an New Android Studio Project

Choose the template

Remember the package name of your Android project. We need to use it later. Then finish the project.

Our Android Project setup is now over. Let’s go to the Firebase Setup.

  • Firebase Setup

To start Firebase, you need to have an Google account. Visit https://console.firebase.google.com/ and login with your Google account credentials. After logged into the Firebase you need to create an project.

Now let’s create our project.

First name your project then continue. If you like to add Google Analytics into your project keep enable or you can add it later. And then create project.

After creating the project, go to Firebase Console and register app by clicking, Add Firebase to your Android App and enter your Android package name. And click register app.

After register the app you must download the google-services.json file and add it to the app directory.

After download the json file, we need to add Firebase SDK into our Android project. I will skip this one, because we can add these into our project later.

Now let’s Begin.

Code Setup

Let’s quickly go over the file structure. The app/src/main folder divided into two folders. Java and Res. Java folder contains all the logic parts and Res folder contains all the UI parts. And Res folder also divided into sub folders. We will talk about this later.

👉Step 1: Install Dependencies

Before we get started make sure you have been import google-services.json file into the project. Download JSON file and import it into the project app level folder. After importing JSON file you have to install Firebase dependencies. Dependencies connect our Android app into the Firebase. To that, go to Android Studio and click Tools in menu bar. And click Firebase. After click Firebase it will open sidebar that will show all of Firebase dependencies.

In this tutorial we only need Firebase Authentication.

After click Firebase Authentication you need to click Connect to Firebase. And it will open browser and you have to sign in thorough the browser. Then you can add dependencies into the project.

That’s It…

👉Step 2: Create Activity

First of all we need to create an empty activity. This activity contains both java and XML files. I have been created four activities :

  • Login Activity
  • Main Activity
  • SignUp Activity
  • Edit Activity

After creating activity first you need to edit your XML (UI) file. This is your app front-end. You can edit whatever you like.

👉Step 3: Edit Java Activity

After creating and modifying the activity XML we need to modify the Java activity. Refer the image below.

👉Step 3: Enable Firebase Authentication

After coding all of the activities we have to enable the Firebase Authentication. Go to your Firebase console and click authentication.

Then click Setup up sign-in method.

After click you can see there is various sign in methods like Google, Facebook, Twitter etc. In this case you have to select Email/Password and click enable. That’s it.

That’s all and our app is ready to go.

GitHub Repository

Source Code available at :

Finally

I hope this will help to you. There are many things to add on this project. I will guide you in next articles how we are going to do that. This is the start and you can all contribute to this project. If you need help follow me on GitHub, LinkedIn or Twitter.

That’s it, thank you! don’t forget to leave a 👏✌️ Use Firebase🔥 Happy Coding✌️❤️

--

--

Pium Sudhara
Pium Sudhara

Written by Pium Sudhara

Senior Cloud Operations Engineer at LSEG☁️💻 | AWS Community Builder | pium.karunasena@gmail.com

No responses yet