GETTING STARTED WITH FIREBASE

Jerry Adeleye
CodebagNG
Published in
4 min readNov 14, 2017

My next articles will be on using Firebase services. But before using any Firebase service on your app, you must first set up your app on the Firebase Console. Start by navigating to the Firebase Console webpage.

Console webpage

Then select “CREATE NEW PROJECT” and name your project.

Create a project

So you can name your project what ever you wish, and also the Firebase console generates an editable project ID for your project.

Once your project is created, you can see the project’s Overview page.

Project overview

Take a moment to look at the console home page for YourProject. You’ll see tabs on the left associated with many of the features we are going to be exploring. Feel free to click on the tabs and see where they lead.

Next you create a Firebase project for android. In the project overview page in the Firebase Console, select “Add Firebase to your Android App”. This opens a dialog window that asks for your app’s Package name and the Debug signing certificate SHA-1. It also asks for an optional App Nickname, which you can keep blank.

Getting the Debug Certificate

You’ll need to add the debug signing certificate too because you’ll implement Google Sign-In for authentication in YourApp. The SHA-1 is a type of hash representation for the debug keystore, which you can get with the keytool command line tool. Which is a long way of saying, the debug keystore is a bunch of letters and numbers, which you should keep secret, that identifies your computer.

On Windows, open the Command Prompt program and type the folowing

keytool -exportcert -list -v \-alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore

On Mac/Linux, open the Terminal and paste:

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

When prompted to input a password, type android and then press Enter. Don’t worry if you don’t see any characters appear on the screen when typing the password, as your command line interface is hiding them on purpose.

After you paste the command and press Enter, you’ll see some text output like the following:

Select the string of numbers and colons after the line that’s labeled “SHA-1:” and copy it. Then paste it in the dialog back in the Firebase Console.

google-services.json

Once you click “Add App”, a google-services.json file should download automatically. The google-services.json file connects your client-side app with your specific Firebase project that will handle the server-side components of your app.

Once the download is complete, move the google-services.json file to the app directory of the FriendlyChat project. In Android Studio, you can select the “Project” view in the top-left corner of the Project navigation view, and then open the app directory. You can then drag the google-services.json file into the Android Studio project. You should end up with a project file tree like the following screenshot:

Next is to add the firebase SDK to the app by adding a few key dependencies to Gradle. In the project’s root Gradle file build.gradle, you add the required Google services plugin. In the documentation for adding Firebase to your Android project, you could scroll down and get that exact plugin,

buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.1.1' // google-services plugin
}
}

allprojects {
// ...
repositories {
// ...
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}

So you copy it and add it to the dependencies.

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:11.6.0'

// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

The Google Services plugin is what reads the configuration information for the google-services.json file that you added before.

You should also add the dependencies for the Firebase SDKs you want to use. It is recommended to start with com.google.firebase:firebase-core, which provides Google Analytics for Firebase functionality. See the list of available libraries.

Once you go ahead and sync, you effectively added the Firebase SDK dependencies to your app.

--

--