firebase-database Getting started with firebase-database Add Firebase to Your Android Project

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Here the steps required to create a Firebase project and to connect it with an Android app.

Add Firebase to your app

  1. Create a Firebase project in the Firebase console and click Create New Project.

  2. Click Add Firebase to your Android app and follow the setup steps.

  3. When prompted, enter your app's package name.
    It's important to enter the package name your app is using; this can only be set when you add an app to your Firebase project.

  4. At the end, you'll download a google-services.json file. You can download this file again at any time. ( this file is located under project setting in Firebase console).

  5. Switch android studio View to Project and paste google-service.json file under app folder

The next step is to Add the SDK to integrate the Firebase libraries in the project.

Add the SDK

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 may have already done this as part of adding Firebase to your app.

  1. Add rules to your root-level build.gradle file, to include the google-services plugin:
buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

Then, in your module Gradle file (usually the app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin:

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ...
  compile 'com.google.firebase:firebase-core:9.4.0'//THIS IS FOR ANALYTICS
  compile "com.google.firebase:firebase-database:11.0.2" 
}

// BELOW STATEMENT MUST BE WRITTEN IN BOTTOM
apply plugin: 'com.google.gms.google-services'

Notes:

  • Data cannot be read/write without Authenticating. If you want it without authentication. Change rules in Database firebase console.

    { "rules": { ".read": true, ".write": true } }

  • Add internet permission in Manifest

  • Upgrade Google Play Services and Google Repository



Got any firebase-database Question?