Using the Firebase database for storing data in Android.

1. Firebase database

Firebase is a real time data base which allows to store tree of lists of objects. It allows to synchronize data between different devices. It is a NoSQL JSON database.

You can find it under: https://console.firebase.google.com/

2. Configure firebase

Logon to https://console.firebase.google.com/ and press Add Firebase to your Android app.

3. Integrating into your application

Add the following gradle dependencies to your general gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    // more stuff
    dependencies {
        // classpath com.android.tools.build:gradle entry as before
        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
    }
}

 // more stuff

Add the following gradle dependencies to your app gradle file

dependencies {
  // ... more stuff
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
}

apply plugin: 'com.google.gms.google-services'

4. Access

Access to your Firebase Database is configured by a set of rules written in a JSON configuration language. == Exercise: Building an Android application using the firebase database

5. Create a new project

Create a new project with the com.vogella.android.firebaseexample top level package.

6. Configure firebase

Logon to https://console.firebase.google.com/ Create a new project and call it vogellachat.

In your new project, select Add Firebase to your Android app.

For this you need to get the SHA-1 for your debug keystore:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v -storepass android

Enter the package and your SHA-1 into the webmask and press Register app.

Firebase registration

Download the google-services-json file and copy it into the root of your Android app model.

Firebase registration

7. Integrating into your application

Add the following gradle dependencies to your general gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    // more stuff
    dependencies {
        // classpath com.android.tools.build:gradle entry as before
        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
    }
}

 // more stuff

Add the following gradle dependencies to your app gradle file

dependencies {
  // ... more stuff
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
}

apply plugin: 'com.google.gms.google-services'

7.1. Configure database access

Select Sign-In Method under authentication and enble Google.

Sign-in methods
Sign-in methods

Open the Rules of your database.

Access rules for the database

9. vogella training and consulting support

Copyright © 2012-2019 vogella GmbH. Free use of the software examples is granted under the terms of the Eclipse Public License 2.0. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.