5 minute quickstart

Android Quickstart

Create an account

The first thing you need to do to get started with Firebase is sign up for a free account. A brand new Firebase will automatically be created for you with its own unique URL ending in firebaseio.com. We'll use this URL to store and sync data.

Install Firebase

To use Firebase in your Android application you can add a dependency to Gradle or Maven in your project or download the latest SDK.

With version 1.1, Firebase has different SDKs for Android and the JVM. This sections handles Firebase for Android. If you are developing on the JVM please add a dependency to firebase-client-jvm instead.

Using Gradle or Maven

We publish builds of our Android and Java SDK to the Maven central repository. To install the library inside Android Studio, you can simply declare it as dependency in your build.gradle file:

dependencies {
    compile 'com.firebase:firebase-client-android:2.2.4+'

If you are getting a build error complaining about duplicate files you can choose to exclude those files by adding the packagingOptions directive to your build.gradle file:

android {
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'

If you use Maven to build your application, you can add the following dependency to your pom.xml:


Download and Install

You can grab the latest Firebase SDK here:
Download Firebase Android SDK

After downloading the JAR, place it on your application's classpath. Typically, this is in your libs folder. Depending on your IDE, you may need to explicitly add the library to your project as a dependency.

Add Android Permissions

The Firebase library requires the android.permission.INTERNET permission to operate. Your app will not work unless you add this permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />

Setup Firebase on Android

The Firebase library must be initialized once with an Android context. This must happen before any Firebase reference is created or used. You can add the Firebase setup code to your Android Application's or Activity's onCreate method.

public void onCreate() {
    // other setup code

Read & Write to your Firebase

To read and write data from your Firebase, we need to first create a reference to it. We do this by passing the URL of your Firebase into the Firebase constructor:

Firebase myFirebaseRef = new Firebase("https://<your-firebase>.firebaseio.com/");

There are several other ways to create a reference to a location in your Firebase. These are all explained in our Understanding Data document.

Writing Data

Once we have a reference to your Firebase, we can write any Boolean, Long, Double, Map<String, Object> or List object to it using setValue():

myFirebaseRef.child("message").setValue("Do you have data? You'll love Firebase.");

Our documentation on saving data to Firebase explains the different write methods our API offers and how to know when the data has been successfully written to your Firebase.

Reading Data

Reading data from your Firebase is accomplished by attaching an event listener and handling the resulting events. Assuming we already wrote to myFirebaseRef above, we can retrieve the message value by using the addValueEventListener method:

myFirebaseRef.child("message").addValueEventListener(new ValueEventListener() {

  public void onDataChange(DataSnapshot snapshot) {
    System.out.println(snapshot.getValue());  //prints "Do you have data? You'll love Firebase."

  @Override public void onCancelled(FirebaseError error) { }

Call getValue() on the DataSnapshot returned from the callback to access the returned object.

In the example above, the value event will fire once for the initial state of the data, and then again every time the value of that data changes. You can learn more about the various event types and how to handle event data in our documentation on reading data.

Add Authentication

Firebase provides full support for authenticating users. For common login options, such as email and password, Facebook, Twitter and Google, checkout out guide on User Authentication provides a quick way to get started. More advanced users may want to use custom login for complete control over user management and authentication.

Use Firebase to manage your authentication

Secure Your Firebase

Use our powerful expression-based Security and Firebase Rules to control access to your data and validate input:

  ".read": true,
  ".write": "auth.uid === 'admin'",
  ".validate": "newData.isString() && newData.val().length < 500"

Firebase enforces your Security and Firebase Rules consistently whenever data is accessed. The rules language is designed to be both powerful and flexible, so that you can maintain fine-grained control over your application's data.

What's Next?