Firebase - YooEunseok/Graduation_Project_GARVIS GitHub Wiki

Firebase Real-time Database

Save and synchronize your data to a NoSQL cloud database. Data is synchronized in real time across all clients and data is also available when apps are offline. The Firebase real-time database is a cloud hosting database. The data is stored in JSON and synchronized in real time to all connected clients. When cross-platform apps are built with iOS, Android, and JavaScript SDK, all clients share a single real-time database instance and receive the latest data with automatic updates.

Installation and Setup on Android

Connect apps to Firebase

Adding Firebase to an Android project

Create Database

  1. Navigate to the Real-Time Database section of the Firebase Console. You are prompted to select an existing Firebase project. Follow the Create Database workflow.

  2. Select the starting mode for the Firebase security rule.

  • Test mode : This is useful when starting mobile and web client libraries, but allows anyone to read and overwrite data. After completing the test, you must review the Understanding Firebase Real-Time Database Rules section. Select a test mode to launch the Web, iOS, or Android SDK.
  • Lock mode : Deny all reads and writes from mobile and web clients. An authenticated application server can still access your database.
  1. Select the revision of the database. Depending on the selected edition, the database namespace is <databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app.

  2. Click Finish

Add real-time database SDKs to apps

Use Firebase Android BoM to declare dependencies of the real-time database Android library in a module (app-level) Gradle file (typically app/build.gradle).

dependencies { 

    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:28.0.1')

    // Declare the dependency for the Realtime Database library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-database'
}

Real-time database rule configuration

Can define the structure of data, how it is indexed, and the conditions under which data can be read and written in the declarative rule language provided by real-time databases.


Add Firebase to Android project

Basic Requirements

  • Install or update the Android studio to the latest version.
  • Verify that your project meets the following requirements:
    • API level 16 (Jelly Bean) or higher targeting
    • Using Gradle 4.1 or later
    • Using Jetpack (AndroidX) that meets the following version requirements
      • com.android.tools.build:gradle v3.2.1 or later
      • compileSdkVersion 28 or later
    • Set up a physical instrument or run the app using an emulator. To use the Firebase SDK with dependencies for the Google Play service, you must have the Google Play service installed on your device or emulator.
    • Log in to Firebase using your Google account.

Using the Firebase Console to Add Firebase

To add Firebase to an app, you must perform operations in both the Firebase Console and open Android projects. For example, you need to download the Firebase configuration file from the console and move it to an Android project.

1. Creating a Firebase Project

To add Firebase to the Android app, first create a Firebase project to connect to the Android app.

  1. Navigate to the Firebase Console. https://console.firebase.google.com/

  2. Click 'Add project' and then enter project name

  1. (Optional) If you create a new project, you can modify the project ID.

  2. Click Continue.

  3. (Optional) Set up Google Analytics in your project so that you can optimize your environment using the following Firebase products.

  4. Click Create Project. If you are using an existing Google Cloud project, click Add Firebase.

2. Register an app with Firebase

To use Firebase with an Android app, you must register the app with the Firebase project. App registration usually means adding an app to a project.

  1. Navigate to the Firebase Console. https://console.firebase.google.com/

  2. Click the Android icon or Add App at the center of the Project Overview page to start the setup workflow.

  1. In the Android Package Name field, enter a package name for the app. (Optional) Enter other app information (App Nickname and Debug Signature Certificate SHA-1).
  1. Click 'Register App'.

3. Add Firebase Configuration File

  1. Add the Firebase Android configuration file to the app.
  • Click Download Google-services.json to import the Firebase Android configuration file google-services.json.
  • Move the configuration file to the module (app-level) directory of the app.
  1. Add the Google-services plug-in to the Gradle file so that the app can use the Firebase product.
  • In the root-level (project-level) Gradle file (build.gradle), add a rule that includes the Google Service Gradle plugin. Make sure you also have Google's Maven repository.

'''

buildscript {

    repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
    }

    dependencies {

        // ...
        // Add the following line:
        classpath 'com.google.gms:google-services:4.3.8'  // Google Services plugin
    }
}

allprojects {
    // ...
    repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
        // ...
    }
}

'''

  • Apply the Google Service Gradle plug-in in the module (app-level) Gradle file (typically app/build.gradle).

'''

apply plugin: 'com.android.application'
// Add the following line:
apply plugin: 'com.google.gms.google-services' // Google Services plugin

android {
    // ...
}

'''

4. Add a Firebase SDK to an App

  1. Use Firebase Android BoM to declare the dependency of the Firebase product you want the app to use. The module (app-level) Gradle file (typically app/build.gradle) declares the dependent entry.
dependencies {
      // ...
      
      // Import the Firebase BoM
      implementation platform('com.google.firebase:firebase=bom:28.0.1')

      // When using the BoM, you don't specify versions in Firebase library dependencies

      // Declare the dependency for the Firebase SDK for Google Analytics
      implementation 'com.google.firebase:firebase-analytics'

      // Declare the dependencies for any other desired Firebase products
      // For example, declare the dependencies for Firebase Authentication and Cloud Firestore
      implementation 'com.google.firebase:firebase-auth'
      implementation 'com.google.firebase:firebase-firestore'
    }

  1. Synchronize apps to see if all dependent items have the required version.

Using Firebase in this project

Run the firebase instructions described above sequentially.

Click Tools -> Firebase in Android Studio.

Click 'Authentication' for users to log in to Google, 'Realtime Database' for database connections, and 'Cloud Functions for Firestore' for dialogflow.

Proceed 'connect to firebase' for the above mentioned three items.

⚠️ **GitHub.com Fallback** ⚠️