Configure the Build Environment

To leverage FCM, you need to configure your project to use the libraries provided by the Google Play services.

Configuring build.gradle (project)

Open the build.gradle file in the project root directory and add classpath 'com.google.gms:google-services:3.0.0' in the buildscript/dependencies.

The file should be now like this:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.1'
        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
    }
}

allprojects {
   ...

3.0.0 is the latest working version at the time of updating this document. If the newer version is available, you should be able to set it with no problem (but you might get a conflict error with the firebase-messaging and/or play-services-gcm set in the next step). You can also specify + to apply the latest version, but note that this might put some unexpected updates in your project.

Configuring build.gradle (module)

Open the build.gradle file located under the build target module (i.e., under the app directory by default) and edit the file as follows:

  • Add implementation or compile lines in the dependencies section.
  • Add apply plugin: 'com.google.gms.google-services' at the root level.

The configuration to be added depends on the version of your Android Studio. The file should be now like this:

  • apply plugin: 'com.android.application'
    
    android {
        ...
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        ...
        implementation 'com.google.firebase:firebase-messaging:9.6.1'
        implementation 'com.google.android.gms:play-services:9.6.1'
    }
    
    apply plugin: 'com.google.gms.google-services'
  • apply plugin: 'com.android.application'
    
    android {
        ...
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        ...
        compile 'com.google.firebase:firebase-messaging:9.6.1'
        compile 'com.google.android.gms:play-services:9.6.1'
    }
    
    apply plugin: 'com.google.gms.google-services'

9.6.1 is the latest working versionat the time of updating this document. If the newer version is available, you should be able to set it with no problem (just like the google-services).

The play-services will be used in a process to check if the Google Play services exist on the device. Such a process is unnecessary in using the FCM feature only but the Firebase documentation recommends checking the existence of the services.

Confirm the dependencies section includes the firebase-messaging entry if you modify build.gradle according to the instruction on the Firebase console.

Checking google-services.json

Confirm the app directory of the project contains google-services.json. This file has been copied to the directory in the step described in Create a Firebase Project.

Reflecting the configuration

When you are done with the above configurations, click the "Sync Now" on the top of the screen to reflect the changes. Now the libraries are automatically downloaded and referenced from the program.

This is all for the setting. Let us move to the next step: Configure the Manifest File.


<< Configure Kii Cloud Configure the Manifest File >>