Setup Firebase in Flutter (Visual Guide)
Last updated: 2020-07-25
This guide was tested on Flutter 1.17.5
.
Flutter 1.17.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 8af6b2f038 (4 weeks ago) • 2020-06-30 12:53:55 -0700
Engine • revision ee76268252
Tools • Dart 2.8.4
Firebase Account Setup
Create Firebase Project
Set Project's Name
Configure Firebase Analytics
Select Your Target: iOS or Android
Register App
Download Firebase Config File
Add Firebase SDK
In android/build.gradle
(root-level / project-level)
buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
// ...
dependencies {
// ...
// Add the following line:
classpath 'com.google.gms:google-services:4.3.3' // Google Services plugin
}
}
allprojects {
// ...
repositories {
// Check that you have following line (if not, add it):
google() // Google's Maven repository
// ...
}
}
In android/app/build.gradle
(app-level)
// Add the following line:
apply plugin: 'com.google.gms.google-services' // Google Services plugin
android {
// ...
}
// ...
Finalize Firebase Setup
Setup Firestore Database
Create Database
Set Database Location
Add Entries to Database
Configure Your Flutter App
Add FlutterFire plugin to pubspec.yaml
dependencies:
flutter:
sdk: flutter
firebase_core:
cloud_firestore:
Run flutter packages get
.
Troubleshootings
Error Plugin project :firebase_core_web not found
Add the following content to android/app/settings.gradle
:
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
Error D8: Cannot fit requested classes in a single dex file
Enable multidex support by adjusting android/app/bundle.gradle
:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}