
Video by Handlebar Labs.
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-firebaseThe command adds various lines of code throughout the android/ directory, which are
needed to install the React Native Firebase module.
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:
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:
Once complete, the file should have been added under android/app/google-services.json.
To manually add the config file, you'll first need to download it from the Firebase console:
The downloaded file show be added to your project at android/app/google-services.json.
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'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"
...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.
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.zipandroid/build.gradle, check that you have added the google() buildscript repository:buildscript {
repositories {
google() // <-- Check this line exists and is above jcenter
jcenter()
// ...
}
// ...
}android/build.gradle update Android build tools to version 3.1.3:classpath 'com.android.tools.build:gradle:3.1.3'android/app/build.gradle, ensure all your compile statements are now implementation, e.g.implementation project(':react-native-firebase')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"
}
}
}TODO