Skip to content

Setup Firebase

Firebase is Google’s cross-platform app development platform. It provides fully managed backend service infrastructure for web based, android or iOS applications.

Firebase provides extensions for common development tasks like authentication, payments, email, etc  —  which can be added per project basis.

Create Firebase Project

  1. Sign in into your Google account.

  2. You need to create a Firebase project, if you don’t already have one. Go to Firebase console here - create a new project. Example: flutter-starter-kit. Feel free to disable Google Analytics for this project. Either way, it will not matter - you can enable it later from Project Settings → Integrations.

    Create Firebase Project

Required Tools for Firebase - Flutter integration

Firebase CLI

Installing Firebase CLI locally will help you manage, test and deploy Firebase project from your command line. It is required to perform Firebase-Flutter integration as we will be modifying Firebase resources through our runtime environment.

To download and install Firebase CLI, you have two options:

Option 1: Through node package:

Terminal window
npm install -g firebase-tools

Option 2: Through Standalone Binary without any dependency

Terminal window
curl -sL firebase.tools | bash

Verify your installation by running firebase --help. More help on Firebase tools can be found here: https://firebase.google.com/docs/cli.

Log into Firebase with your Google account using this command:

Terminal window
firebase login

FlutterFire CLI

FlutterFire CLI is used to create Firebase app for target development environment (Android/iOS/Web/macOS) in your existing Firebase project. It is also possible to create new project through FlutterFire.

Run this command from any directory to install:

Terminal window
dart pub global activate flutterfire_cli

This does not add any new file in your project, it is a separate package. Add this to PATH: export PATH="$PATH:$HOME/.pub-cache/bin" to make sure flutterfire_cli is available in your terminal.

Add Firebase to your Flutter project

This command runs the worflow to add apps to your Firebase project and generate necessary files for your Flutter project to use Firebase:

Terminal window
flutterfire configure
  1. Asks you to select the platforms (iOS, Android, Web) that you want to support in your Flutter app. For each selected platform, the FlutterFire CLI creates a new Firebase app in your Firebase project.

  2. Creates a Firebase configuration file (firebase_options.dart) and adds it to your lib/ directory.

    👋 Note: firebase_options.dart file is already included in the project. This command is supposed to override the existing file and add your selected platforms. It will also make changes in ios and android folders.

  3. Generates a google-services.json file for each platform that you selected.

  4. Adds the necessary dependencies to your pubspec.yaml file.

  5. Adds the necessary code to your AndroidManifest.xml file for Android.

After running the command, you should clean and run your project to make sure everything is working.

Terminal window
flutter clean
flutter run

Congrats! You have successfully added Firebase to your Flutter project!

Common errors

  1. Flutter Android: One or more plugins require a higher Android NDK version. Link: here.

    Solution: Choose the latest NDK version from here and update in android/app/build.gradle.

  2. Common error when setting up on iOS: Automatically assigning platform iOS with version 12.0 on target Runner because no platform was specified. Please specify a platform for this target in your Podfile. See https://guides.cocoapods.org/syntax/podfile.html#platform.

    OR

    Error: The plugin "firebase_auth" requires a higher minimum iOS deployment version than your application is targeting. To build, increase your application's deployment target to at least 13.0 as described at https://docs.flutter.dev/deployment/ios

    Solution: Go to ios/Podfile and add platform :ios, '13.0' to the top of the file to fix this error. This is already done in the project.

References

  1. https://firebase.google.com/docs/flutter/setup
  2. https://firebase.google.com/docs/projects/learn-more