Documentation

  1. Documentation/
  2. v4.x.x/
  3. Installation/
  4. Android Installation

Android Installation

Video by Handlebar Labs.

Linking React Native Firebase

First off link the project with React Native. Luckily, this can be achived using a simple command from the root of your project:

react-native link react-native-firebase

The command adds various lines of code throughout the android/ directory, which are needed to install the React Native Firebase module.

Setting up google-services.json config file

Firebase provides us with a json file named google-services.json, which contains all of the information required to connect with your Firebase project. The file will live in our android/app directory.

There are a couple of ways we're able to add this file to our project:

Via Android Studio

If you're using Android Stuido version 2.2 or later, you can complete the process quite easily. After opening your projects android/ directory in Android Stuido:

  1. Click Tools > Firebase to open the Assistant window.
  2. Click to expand one of the listed features (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).
  3. Click the Connect to Firebase button to connect to Firebase and add the necessary code to your app.

Once complete, the file should have been added under android/app/google-services.json.

Manually

To manually add the config file, you'll first need to download it from the Firebase console:

  1. Sign in to Firebase and open your project.
  2. Click the Settings icon and select Project settings.
  3. In the Your apps card, select the package name of the app you need a config file for from the list.
  4. Click google-services.json.

The downloaded file show be added to your project at android/app/google-services.json.

Parsing the config file

In order for Android to parse this file, add the google-services gradle plugin as a dependency to your project in the project level android/build.gradle file:

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

To initialize the plugin, add the following to the very bottom of your android/app/build.gradle file:

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

Adding Firebase modules

React Native Firebase only interacts with Firebase, it does not install the Firebase modules. Add the following lines to the android/app/build.gradle file to install the required native Google Play Services and Firebase SDKs:

dependencies {
  // This should be here already
  implementation project(':react-native-firebase')

  // Firebase dependencies
  implementation "com.google.android.gms:play-services-base:15.0.1"
  implementation "com.google.firebase:firebase-core:16.0.1"

  ...

Updating Gradle

In later Android Firebase versions (v12+), the Gradle version required is v4.4. To ensure you're using this version, a few changes are needed.

  1. In android/gradle/wrapper/gradle-wrapper.properties, update the gradle URL to gradle-4.4-all.zip:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
  1. In android/build.gradle, check that you have added the google() buildscript repository:
buildscript {
    repositories {
        google()  // <-- Check this line exists and is above jcenter
        jcenter()
        // ...
    }
    // ...
}
  1. In android/build.gradle update Android build tools to version 3.1.3:
classpath 'com.android.tools.build:gradle:3.1.3'
  1. In android/app/build.gradle, ensure all your compile statements are now implementation, e.g.
implementation project(':react-native-firebase')
  1. When running your app from within Android Studio, you may encounter Missing Byte Code errors. This is due to a known issue with version 3.1.x of the android tools plugin: https://issuetracker.google.com/issues/72811718. You'll need to disable Instant Run to get past this error.

Update Google Play service maven repository

Google Play services from 11.2.0 onwards require their dependencies to be downloaded from Google's Maven respository so add the required reference to the repositories section of the project level android/build.gradle:

allprojects {
    repositories {
        mavenLocal()
        google() // <-- Add this line above jcenter
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

Install modules

TODO

unfold_more