Latest Articles

Integrating Firebase in Android project and Register User with Authentication

Today, we are going to implement a simple android application for Android developers india to integrate User Registration using firebase authentication. The authentication process will be achieved by using users email addresses and passwords. This is made possible by the firebase authentication SDK that has methods that can be used to create and manage users who use their email addresses and passwords for signing in. It is also equipped with handling password reset emails. To achieve our agenda, we first need to integrate firebase in our android project.

Android firebase

Integrating firebaseinto your android project:

1.Integrate a firebase manually

You’ll need to add a firebase manually if you are using android studio’s older version which is below 2.2 but if you are using the 2.2 or above versions you’ll simply need a firebase assistant to connect your android application with firebase. For doing this steps are discussed in a second heading.

First create android project

File ->New->New project.While filling the project details ,make sure to use the same package name in a firebase console. We are using

You need to create a firebase project in a firebase console.Go to this link You’ll see a “Welcome to firebase” window.



1. Click “add project”

2. Use the same project name which you used while creating your android project. Our project name is “FirebaseAndroid”.


3. Select your country and click on a buttonCREATE PROJECT.

4. Click “Add Firebase to your Android app” and follow the steps in a from.


5. Make sure to give thesame package name that you used in your android project in which you are going to integrate the firebase. In our case package name is “”.

6. Leave other two fields empty as they are optional and click the REGISTER APP button.


7. Download the google-services.jsonfile and place this file in your project’s module folder, typically/app. Your project won’t build without this file, So you can download this file at any time using this link


8. After clicking on a CONTINUE button , you’ll get the gradle instructions that you’ll need to put in your Android studio project’s files.


9. Add Firebase SDK

• Open build.gradle file at your root level, to include the google-services plugin.


dependencies {
classpath'' // google-services plugin

• As we are implementing firebase authentication in our android app so we’ll add firebase authentication dependency in a app/build.gradle file and apply plugin line at the bottom of the file to enable the Gradle plugin.


dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ''
//firebase authentication dependency
compile ''

apply plugin: ''


Now sync the project with gradle.

You can use other features of firebase as per your own requirements by using other dependencies. See the list of available libraries below.

Gradle Dependency Line



Realtime Database

Cloud Firestore


Crash Reporting


Cloud Messaging

Remote Config

Invites and Dynamic Links


App Indexing

Performance Monitoring

Cloud Functions for Firebase Client SDK

ML Kit (Vision)

ML Kit (Custom Model)

2.IntegrateFirebase using firebase Assistant:

Open Android Studio project in which you want to add firebase

Click Tools->Firebase then click to expand the listed features in a Firebase Assistant


Select the type of firebase feature you want to use in your app.We are using firebase auth so we have clicked Authentication.


Click the Connect to Firebase button to connect to Firebase and add the necessary code to your app, and if you have already registered your project on a Firebase console then click on “Add Firebase Authentication to your App”.


Click on “Accept Changes” button to add the firebase-core library which helps you to add authentication dependencies to your application.


Register User with using Firebase authentication

Click on a link to visit firebase panel

Click on “Authentication” on the left side of the firebase panel.


Click on “Set Up Sign In Method” button.


Now click onEmail/Password provider , click enable and save it.


If you would like to integrate the Firebase libraries into one of your own projects, you need to perform a few basic tasks to prepare your Android Studio project.You have already done the integration steps above including dependencies in build.gradlefiles , now come to project implementation.

Android Project Implementation:

Now open the android studio’s project you have created.My project was “FirebaseAndroid”.

Open activity_main.xml file from your project res/layout folder, add the below code in that file


<?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#D3D3D3"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/register" android:textStyle="bold" android:textSize="30sp" android:paddingLeft="60dp" android:paddingTop="50dp" /> <EditText android:id="@+id/editText1" android:layout_width="304dp" android:layout_height="wrap_content" android:ems="10" android:hint="@string/email" android:textSize="25sp" android:paddingTop="70dp" android:inputType="textEmailAddress" /> <EditText android:id="@+id/editText2" android:layout_width="304dp" android:layout_height="wrap_content" android:ems="10" android:hint="@string/pass" android:textSize="25sp" android:inputType="numberPassword" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:paddingTop="10dp" android:paddingRight="10dp" android:background="#A9A9A9" android:text="@string/reg" /> </LinearLayout>

Add the below code in string.xml file of your project resources folder.


<resources> <string name="app_name">FirebaseAndroid</string> <string name="register">Register Yourself</string> <string name="reg">Register</string> <string name="email">Enter your email</string> <string name="pass">Enter your password</string> </resources>

Open the file of your project and add the below code in it.

package; import; import; import; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import; import; import; import; public class MainActivityextends AppCompatActivity { EditTextemail,pass; Button btn_reg; //defining firebaseauth object private FirebaseAuthfirebaseAuth_obj; private ProgressDialogprogressDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //initializing firebase authentication object firebaseAuth_obj= FirebaseAuth.getInstance(); email = (EditText) findViewById(; pass = (EditText) findViewById(; btn_reg= (Button) findViewById(; progressDialog= new ProgressDialog(this); //attaching listener to button btn_reg.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { user_registration(); } }); } private void user_registration(){ //getting email and password from edit texts and save them in a string variables String entered_email = email.getText().toString().trim(); String entered_password = pass.getText().toString().trim(); //if entered_email and entered_password are empty then prompt user to enter email and pass by showing toast message if(TextUtils.isEmpty(entered_email)){ Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show(); return; } if(TextUtils.isEmpty(entered_password)){ Toast.makeText(this,"Please enter password", Toast.LENGTH_LONG).show(); return; } //if the email and password are not empty //displaying a progress dialog progressDialog.setMessage("Registering Please Wait...");; //creating a new user firebaseAuth_obj.createUserWithEmailAndPassword(entered_email, entered_password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNullTask<AuthResult> task) { //checking if success if(task.isSuccessful()){ //display successful message Toast.makeText(MainActivity.this,"You have successfully registered",Toast.LENGTH_LONG).show(); }else{ //display error message Toast.makeText(MainActivity.this,"error while registering",Toast.LENGTH_LONG).show(); } progressDialog.dismiss(); } }); } }

I have declared the firebase authentication object in this class


And then initialized the object inside onCreate() method.

firebaseAuth_obj= FirebaseAuth.getInstance();

Bind all the layout views with java file.

email= (EditText) findViewById(;
pass = (EditText) findViewById(;
btn_reg= (Button) findViewById(;

Initialized the progress dialog box to use it later in the code.

progressDialog= new ProgressDialog(this);

Once the user_registration() method will be called , it will first check the email and password fields, if they are not empty then will seta message on a dialog box "Registering Please Wait... "by calling a function setMessage() and will start creating a user by calling a method createUserWithEmailAndPassword() with the help of “firebaseAuth_obj”

object of a FirebaseAuthclass. In this method we’ll pass two parameters email and password which are necessary for user registration.

The OnCompleteListener will check the task is completed or not.

//creating a new user
firebaseAuth_obj.createUserWithEmailAndPassword(entered_email, entered_password)
            .addOnCompleteListener(this, new OnCompleteListener() {
public void onComplete(@NonNullTask task) {
//checking if success
//display successful message
Toast.makeText(MainActivity.this,"You have successfully registered",Toast.LENGTH_LONG).show();
//display error message
Toast.makeText(MainActivity.this,"error while registering",Toast.LENGTH_LONG).show();

You can’t perform network-related operations without the internet permission, so add the following line to your project’s manifest file:


Running Android Application:

Click on a Register button and you’ll get the success message , then go to the firebase console and check the registered user there.


Congratulations,Your registration is done.