Skip to main content

CLI

Notice

This page is archived and might not reflect the latest version of the FlutterFire plugins. You can find the latest information on firebase.google.com:

https://firebase.google.com/docs/flutter/setup

The FlutterFire CLI is a useful tool which provides commands to help ease the installation process of FlutterFire across all supported platforms.

Installation#

The FlutterFire CLI depends on the underlying Firebase CLI. If you haven't already done so, make sure you have the Firebase CLI installed on your machine. If not, make sure you have node.js on your machine and Install the Firebase CLI via npm by running the following command:

npm install -g firebase-tools

Learn more about the Firebase CLI in the documentation.

Next, install the FlutterFire CLI by running the following command:

dart pub global activate flutterfire_cli

Once installed, the flutterfire command will be globally available.

Usage#

note

If you initialize your Firebase app from Dart, you may receive warning logs from the native iOS Firebase SDK indicating no Firebase app has been configured (i.e. GoogleService-Info.plist). You can safely ignore these logs if you're initializing your Firebase app from Dart.

FlutterFire can be initialized from Dart on all platforms using Firebase.initializeApp, however the options for different platforms can vary. The FlutterFire CLI can help, by generating a file (by default called firebase_options.dart) which can be used when calling the initialization method.

The FlutterFire CLI extracts information from your Firebase project and selected project applications to generate all the configuration for a specific platform.

In the root of your application, run the configure command:

flutterfire configure

The configuration command will guide you through a number of processes:

  1. Selecting a Firebase project (based on the .firebaserc file or from the Firebase Console).
  2. Prompt what platforms (e.g. Android, iOS, macOS & web) you would like configuration for.
  3. Identify which Firebase applications for the chosen platforms should be used to extract configuration for. By default, the CLI will attempt to automatically match Firebase apps based on your current project configuration.
  4. Generate a firebase_options.dart file in your project.

Once complete, you can now import the generated file and provide it to the initializeApp method:

lib/main.dart
// Import the generated file
import 'firebase_options.dart';

Then, provide the current platform options via the currentPlatform getter from the DefaultFirebaseOptions class:

await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
note

If you add support for a new platform in your Flutter app (e.g. adding Android when your app previously did not support Android), or if you introduce new Firebase services into your app (e.g. adding firebase_database) then you should reconfigure Firebase for your application again via the CLI (flutterfire configure).

Commands#

Configure#

Generates a firebase_options.dart file which can be provided to the options parameter when Initializing Firebase.

flutterfire configure

The command supports the following option arguments:

ArgumentAliasDescription
--project-pSets the Firebase Project ID to use. By default, the CLI will attempt to fetch the project defined in the .firebaserc file, or prompt you to select the project from the Firebase Console.
--account-eSets the email address which should be used to authenticate with Firebase against. By default, this will use the primary account defined on the Firebase CLI.
--out-oSpecifies the path & file name for the generated file. Defaults to "lib/firebase_options.dart".
--ios-bundle-id-iThe bundle identifier of your iOS app, e.g. "com.example.app". If no identifier is provided, an attempt will be made to automatically detect it from your "ios" folder (if it exists).
--macos-bundle-id-mThe bundle identifier of your macOS app, e.g. "com.example.app". If no identifier is provided, an attempt will be made to automatically detect it from your "macos" folder (if it exists).
--android-package-name-aThe package name of your Android app, e.g. "com.example.app". If no package name is provided, an attempt will be made to automatically detect it from your "android" folder (if it exists).
--[no-]apply-gradle-plugin-gWhether to add the Firebase Gradle plugin to your Android app's build.gradle files and create the google-services.json file in your ./android/app folder. (defaults to on)

Version#

To view the current version of the FlutterFire CLI, run:

flutterfire --version

Updating the CLI#

If your CLI version is no longer the latest published version then you will be prompted to automatically update your CLI to the latest version when you run flutterfire --version. Alternatively you can manually trigger an update via the following command:

dart pub global activate flutterfire_cli

Reporting an issue#

If you have encountered any issues with the CLI, please report them here.