How To Add Firebase To Android

Apr 18, 2018

I have written How To Add Firebase To Android (with existing Google Project) back in Aug 2017, but I will write an updated guide for new project here.

NOTE: the documentation mentioned prerequisites of Android 4.0 (Ice Cream Sandwich) or newer, and Google Play services 15.0.0 or higher.

In Android Studio, goto Tools -> Firebase -> Analytics -> Log an Analytics Event.

Android Studio Firebase Analytics

NOTE: It might seems strange to add Analytics when we want just want to add Firebase, but going through the Analytics wizard will setup Firebase.

Click Connect your app to Firebase. You can Create new Firebase project or Choose an existing Firebase or Google project.

Android Studio Connect your app to Firebase

Upon success, you should see Connected for Step 1.

Android Studio Connect your app to Firebase

NOTE: A file named google-services.json should exist in app/google-services.json. You can't see it in Android view (left project files panel in Android Studio), select Project Files view instead.

NOTE: It seems like the Android Studio wizard automatically create project id (e.g. projectname-eaa23) and storage_bucket (e.g. projectname-eaa23.appspot.com). I believe there is no way change these once created. If the project id matter to you, you might want to explore Manually Add Firebase (I didn't tried this method before) or create your Google Cloud Project first then import the project into Firebase.

Click Add Analytics to your app for Step 2.

Android Studio Add Analytics to your app

The following configrations shall be added:

build.gradle (project-level)

    Add Firebase Gradle buildscript dependency
        classpath 'com.google.gms:google-services:3.1.1'

app/build.gradle

    Add Firebase plugin for Gradle
        apply plugin: 'com.google.gms.google-services'

    build.gradle will include these new dependencies:
        compile 'com.google.firebase:firebase-core:11.8.0'

Android Studio Add Analytics to your app

Edit project build.gradle (the wizard should have auto inserted the following).

buildscript {
    // ...
    dependencies {
        // https://bintray.com/android/android-tools/com.google.gms.google-services/
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

Edit module/app build.gradle (the wizard should have auto inserted the following).

dependencies {
    // https://firebase.google.com/support/release-notes/android
    implementation 'com.google.firebase:firebase-core:12.0.1'
}

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

NOTE: I believe classpath 'com.google.gms:google-services and apply plugin: 'com.google.gms.google-services' is required for all Firebase components.

NOTE: com.google.firebase:firebase-core is a recommended alias for the com.google.firebase:firebase-analytics library. I suspect com.google.firebase:firebase-core is optional if you are not using Firebase Analytics, but I might be wrong or things might change in the future.

NOTE: check Firebase Android Latest Releases

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.