How to Add Android Projects to Google Firebase for Using APIs, Google Analytics…

Tiempo de lectura: 3 minutos

Reading Time: 3 minutes

If we want to use any of the Google APIs in our projects, we first need to add them to Firebase.

The first thing we need to do is register our app in Firebase.

We add a new project and fill in all the required fields.

Once the project is added, we need to create an app linked to the project (multiple apps can be added to use the same configuration).

We choose that our app is Android and fill in the following data.

The Android package name can be found in the classes of our project using the package keyword:

package com.example.test;

We can also find it inside AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test">

Then we can indicate whether we want a nickname for the app.

Finally, it asks for the SHA-1 of the debug signature that we will use to give permission to our app to access GoogleSignIn. To obtain it, follow this tutorial Obtain SHA-1 Fingerprint of debug.keystore in Android (default signing key of Android Studio).

And click on Register App.

Now download the google-services.json file and add it to the project.

To add it, indicate in the explorer tab (it says Android) that we want the project-level view:

Now we are able to see all the project folders, and we need to paste the google-services.json file inside the app folder.

Once the configuration is done, follow the instructions to add the Firebase SDK to our project.

To do this, switch back to the Android view.

Go to Gradle Scripts and open the build.gradle file at the project level (first file).

Now add this line inside dependencies

 dependencies {
bash
Copy code
    classpath 'com.google.gms:google-services:4.3.10'
 
}

Then open the build.gradle file below (App level)

And now add the following at the very top:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

Then go to dependencies and add the following:

implementation platform('com.google.firebase:firebase-bom:30.0.1')
    implementation 'com.google.firebase:firebase-analytics'

And we have added our project to Firebase.

Leave a Comment