Hello friends, in this Android Firebase Tutorial, we will see how we can make User Registration in Android by using Firebase as our App’s backend. I have already posted an Android Firebase Tutorial.
But firebase is now taken by google and things are changed a little. That is why I am again posting this Android Firebase Tutorial. Today we will learn about making User Registration using Firebase Authentication for Android. If you are interested in Swift and iOS then you can go through this Firebase iOS Tutorial.
Table of Contents
What is Firebase?
Firebase is a cloud service provider. It is now under google and this service can replace your whole server side part of your application. In many tutorials we had used MySQL and PHP for our database. But if we will use Firebase we do not need any server side code or configuration. We can directly use firebase. Firebase comes with a bundle of many features.
Features of Firebase?
Android Firebase Tutorial – Video
You can keep on reading this tutorial but if you don’t want reading, you can watch this video. This is not like my other videos. This is a complete explanation of this post. So you can go through this video as well.
Android Firebase Tutorial
So without wasting time lets start our Android Firebase Tutorial. We will start from creating a new project.
From this tutorial you will see screenshots of OS X. 😛 Thanks to you guys, I managed to get MacbookAir with your support. 🙂
Creating an Android Studio Project
- Open Android Studio and Create a New Project. I created FirebaseAuthDemo.
- Now wait for your project, once it is fully loaded we can start working.
- But before we need a app in Firebase Console as well. So switch to your browser from Android Studio.
Adding Firebase to our Project
- Go to firebase.google.com.
- Click on Get Started for Free.
- Now click on create a new project.
- Give your app a name and click on create project.
- Now you will see the Firebase Panel. You need to click on Android Icon here.
- Now you will see a panel here you need to put the package name of your project. You can get the package name from AndroidManifest.xml file. Copy the package name and paste it here and then click on Add App.
- When you click Add App, a file named google-services.json will be downloaded. You need to paste this file inside app directory of your project. See the below image for explanation.
- Now come inside your project level build.gradle file and modify it as follows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.2' //you need to add this line classpath 'com.google.gms:google-services:3.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } |
- Now modify your app level build.gradle file as follows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | apply plugin: 'com.android.application' android { compileSdkVersion 24 buildToolsVersion "24.0.0" defaultConfig { applicationId "net.simplifiedcoding.firebaseauthdemo" minSdkVersion 15 targetSdkVersion 24 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.0.0' } //add the following line apply plugin: 'com.google.gms.google-services' |
- Now sync your project with Gradle.
Adding Firebase Authentication
As in this Android Firebase Tutorial, we are building a user registration application, we need to use Firebase Authentication. So we need to add Firebase Authentication to our project. For this go inside app level build.gradle file and inside dependencies block add the following line.
1 2 3 4 5 6 7 8 9 10 | dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.0.0' //add this line compile 'com.google.firebase:firebase-auth:9.2.1' } |
Again sync your project.
Enabling Email/Password Authentication
- Again go to your firebase panel.
- On the left side menu you will see Auth, click on it.
- Now click on Set Up Sign In Method.
- Now click on Email/Password, enable it and press save.
Creating User Signup Form
- Now we will need to create a form in our activity from where user can Sign Up to our app.
- Come inside your Android Studio Project, and in activity_main.xml write the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="net.simplifiedcoding.firebaseauthdemo.MainActivity"> <LinearLayout android:layout_centerVertical="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <EditText android:id="@+id/editTextEmail" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:hint="Enter email" android:inputType="textEmailAddress" /> <EditText android:id="@+id/editTextPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:hint="Enter password" android:inputType="textPassword" /> <Button android:id="@+id/buttonSignup" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:text="Signup" /> </LinearLayout> </RelativeLayout> |
- The above code will generate the following UI.
Understanding Firebase Signup
This is the main part of this Android Firebase Tutorial. First I will tell you about the methods. As we will be using Firebase Authentication for the user Signup we need these steps to get it done.
Step #1
First we will define a FirebaseAuth object. Then inside method onCreate() we will initialize this object. See the following code snippet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package net.simplifiedcoding.firebaseauthdemo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.google.firebase.auth.FirebaseAuth; public class MainActivity extends AppCompatActivity { //defining firebaseauth object private FirebaseAuth firebaseAuth; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //initializing firebase auth object firebaseAuth = FirebaseAuth.getInstance(); } } |
Step #2
Now we will call the method createUserWithEmailAndPassword() from the FirebaseAuth object. This method take two String parameters for email and password. And we attach a OnCompleteListener on it to check the task is completed or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | private void registerUser(){ //creating a new user firebaseAuth.createUserWithEmailAndPassword("user email here", "user password here") .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { //checking if success if(task.isSuccessful()){ //display some message here }else{ //display some message here } } }); } |
Implementing Firebase Signup
We understood the code. Now lets implement it to make registration work in the activity. Write the following code in your MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | package net.simplifiedcoding.firebaseauthdemo; import android.app.ProgressDialog; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; 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 com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.firebase.auth.AuthResult; import com.google.firebase.auth.FirebaseAuth; public class MainActivity extends AppCompatActivity implements View.OnClickListener { //defining view objects private EditText editTextEmail; private EditText editTextPassword; private Button buttonSignup; private ProgressDialog progressDialog; //defining firebaseauth object private FirebaseAuth firebaseAuth; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //initializing firebase auth object firebaseAuth = FirebaseAuth.getInstance(); //initializing views editTextEmail = (EditText) findViewById(R.id.editTextEmail); editTextPassword = (EditText) findViewById(R.id.editTextPassword); buttonSignup = (Button) findViewById(R.id.buttonSignup); progressDialog = new ProgressDialog(this); //attaching listener to button buttonSignup.setOnClickListener(this); } private void registerUser(){ //getting email and password from edit texts String email = editTextEmail.getText().toString().trim(); String password = editTextPassword.getText().toString().trim(); //checking if email and passwords are empty if(TextUtils.isEmpty(email)){ Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show(); return; } if(TextUtils.isEmpty(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..."); progressDialog.show(); //creating a new user firebaseAuth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { //checking if success if(task.isSuccessful()){ //display some message here Toast.makeText(MainActivity.this,"Successfully registered",Toast.LENGTH_LONG).show(); }else{ //display some message here Toast.makeText(MainActivity.this,"Registration Error",Toast.LENGTH_LONG).show(); } progressDialog.dismiss(); } }); } @Override public void onClick(View view) { //calling register method on click registerUser(); } } |
- Now lastly add internet permission to your AndroidManifest.xml file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.simplifiedcoding.firebaseauthdemo"> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
- Now run your application.
- Click on Signup and if you got the success message. Check your firebase console.
- Bingo! the registration is working fine. You can get my source code from the link below.
So thats all for this Android Firebase Tutorial friends. In the next post we will see about user login and other options like Password Reset, Email Change, Delete Account etc.
And yes feel free to leave your comments if having any confusions regarding this Android Firebase Tutorial. Thank You 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.
Great and detailed tutorial.But how can I add other details to a user during registration? Say i want the user to register with name, birthday, address etc.
u can use HashMap
like that
HashMap dataMap = new HashMap();
dataMap.put(“Name”, strfullname);
dataMap.put(“Username”, strusername);
dataMap.put(“Email”, stremail);
dataMap.put(“Phone”, strphone);
myDatabase.push().setValue(dataMap);
Need a tutorial to explain the use of HashMap to store data like name, username, phone no., and other details with registration and show them in profile activity and then login with that username instead of email.I think you got what i want to do with that.
your tutorial are really awesome and helpful for the starters.Eagerly waiting for your response….
Thank you.
Nice tutorial. My first attempt was with a password of 5 characters and it did not work , but the second try with 10 characters succeeded.
hi i am getting this error: Local module descriptor class for com.google.firebase.auth not found.
add dependencies correctly…..it will work
Did you know that you can go Tools – Firebase and it actually sets up the project for you on Firebase.
Hello, Can you help me? I have a error with firebase auth: Local module descriptor class for com.google.firebase.auth not found. And Google store is missing.
I have a error: Local module descriptor class for com.google.firebase.auth not found. And Google store is missing. Can you help me fix this error please?
wow superb bro…. nice tutorial…. its work completely fine ….
I m getting the error……Registration Error
Local module descriptor class for com.google.firebase.auth not found
I am also getting the same error. Any help?
I’m also getting the error……Registration Error
Local module descriptor class for com.google.firebase.auth not found
Same problem here. Kindly help if it is resolved!
try to register more than 5 characters in email/password. it solves my problem
i followed the all steps and checks many times nut data is not inserted in database everytime shows reg. fail.what is reason?plzz help me
add internet permission in manifest file and add the dependency
implementation ‘com.google.firebase:firebase-auth:16.2.1’
implementation ‘com.google.firebase:firebase-analytics:16.4.0’
implementation ‘com.google.firebase:firebase-core:16.0.8’
Hey I wanted to ask, how to handle if the user is already registered with his email. Will firebase allow new registration with an email that is already registered?
You will get an error if email already exist
looks like you can only register once
Obviously you can only register once..
how come?
great job man. i have a query. please reply
after successful registration, on the registration page the id and password still remains. how to get them blank after successful registration
Nice tutorial brother but i am successful only to register one user in firebase when i tried to enter another than my app display registration failed .Can u pls find the solution for this ?
how to register more than one user plz
its taking too much time and continuously showing message registering please wait…
I think you forgot to add progressDialog.dismiss();
Nice Tutorial Belal,
Registration will work fine. Its bettor to demonstrate login module also
Thanks!
cannot register more than 1 user?
i want to be a good software enginner.
Then Please Stop commenting like this and Study on Your Core buddy
Is there any way to make a list in the aplication wich will show all of the users?
With users i mean the email.
Thnx in advance!
I get Error As
E/EGL_emulation: tid 4868: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
When I click Regisrer Button ProcessDialog goes on processing without end
Great tutorial man , but can u make the tutorial that included upload profile picture instead of just email and password please. Thanks again!
Thank you, sir, your tutorial is very help full for me
how can we retrieve data from “firebase”
and Sir i am working next Project based on “android-fingerprint-authentication”
can u plz help me
Thanks to help but i want to login through github.
how to do ?. please tell me.
how can i create different UI for different user login. in my app i have 3 users : principle, HOD and teachers . Each having different work. teachers apply for leave .. and.. forwarded to HOD(rejects/forward) ..and.. forward to principle(rejects/accepts) and teachers get notified with the status .
Mine is stuck on the progress bar ‘Registering User’
Help pleaaase
How did u fix the problem ?? mine is stuck too
Have u solve this problem of
Local module descriptor class for com.google.firebase.auth not found I can’t find any solution ?
how to register more than one user plz
Hello sir,can you please tell me how can I add user from my application?
howl send email verification with firebase ?
please answer 🙂
why the progressDialog will be continuously progressing then that mail and password is also cannot add to firebase
i need a code of storing fingerprint on database please help me its my final year project
i need a code of storing fingerprint and QR code on database please help me its my final year project
i have legalArgumentException.. why so what my mistake
if i can register user’s email and password in firebase database then how to i verify that email and password in user’s login page..
Hello i need help all things doing correctly but when giving email and password its showing registration error
great job dude. i really loved your work! my question is why is it taking a limited number of characters when i type email.
hi, thank you for the tutoriel .
can you please tell me where can i get the source code.
great tutorial i wanna store more registration details along with username password location dob etc.. how could that can be done any ideas are welcome..
I want to store more details along with email and password how it can be done?
Thnk you so much Sir…
It helps..
but when i m adding the user permission it is throwing some error, but it is working without it.
I am getting some errors .please solve it.
hi there, i have successfully created this app, but when i have tested for if email and password field is empty toast,i clicked the signup button without filling the email and password field and the app is getting crash,please help me with that,
thank you
You need to check this video:
https://www.youtube.com/watch?v=FwUV1R8nKXk&t=10s
It will help you.
Then just put a condition like signup button should only be clickable if the email and pass fields are not blank/null.
So in your onclick listener method first check if the enail pass fields are not blank then run the signup code.
great job. really simple implementation.