Configure Firebase

Prerequisites

  • Install or update Android Studio to its latest version
  • Make sure that your project meets these requirements:
      Targets API level 16 (Jelly Bean) or higher
     
    Uses Android 4.1 or higher
      Uses Jetpack (AndroidX), which includes meeting these version requirements:
       
    com.android.tools.build:gradle v3.2.1 or later
        compileSdkVersion 28 or later
       
    minSdkVersion 26 or later

Configure Firebase project and API key

Start by configuring your Firebase Cloud Messaging (FCM) account to receive push notifications and messages.

Next, configure your Firebase project and obtain an API key and Sender ID.

To authenticate a service account and authorize access to Firebase services, you need to generate a private key file in JSON format:

  • In the Firebase console navigate to Settings > Service Accounts
  • Select Generate New Private Key
  • Securely store the JSON file containing the key
  1. Copy the content of your JSON key to the Firebase service account key under the Android SDK FIREBASE SETTINGS tab in the Proto AICX platform
1048

Add Firebase to your Android project

To add Firebase to your Android app, complete the following steps:

  1. Enable Firebase services in your Android app by adding the google-services plugin and kotlin-gradle plugin to your project-level build.gradle file
buildscript {
    
    // ...

    dependencies {
        // ...
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72'
        classpath 'com.google.gms:google-services:4.3.5'
    }
}
  1. Add FCM dependency firebase-messaging to your application module build.gradle

📘

Note

The Proto Android SDK already contains the Firebase BoM dependency so you do not have to add the BoM dependency.

     implementation 'com.google.firebase:firebase-messaging'

Next, add this line at the bottom of your build.gradle file:

     // Needs to be at the bottom of file.
     apply plugin: 'com.google.gms.google-services'
  1. Download google-services.json file from your Google Firebase Console and put it into your app folder in your Android project

Add Proto SDK to your Android project

To add the Proto SDK to your Android app, complete the following steps:

  1. Add the URL location of our Gitlab Package Registry to the project-level build.gradle file, 24238735 is the ID of the Gitlab project that host our artifacts:
allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://gitlab.com/api/v4/projects/24238735/packages/maven"
        }
    }
}
  1. In the app module build.gradle file, add this line to the dependencies section:
dependencies {
        //....
    	implementation 'cx.proto.sdk:protochat:1.0.0'
}
  1. In the app module build.gradle file, add the kotlin-android plugin to top of the file:
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
  1. Enable Java 8 by adding the below configs to build.gradle:
    android {

        packagingOptions {
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/INDEX.LIST'
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        kotlinOptions {
            jvmTarget = '1.8'
        }
    }
  1. Finally, enable Firebase Messaging Service by declaring it between the application tags in the Android Manifest:
    <application
        ....
        ....>
        <service
            android:name="cx.proto.sdk.services.firebase.FirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
    </application>