<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-setup-flutter-firebase-with-multiple-flavors-using-the-flutterfire-cli-ye1rwts5c" -->

---
title: How to Setup Flutter & Firebase with Multiple Flavors...
description: Learn how to set up multiple Firebase environments for a Flutter app with different flavors using the FlutterFire CLI. The guide covers creating separate...
canonical: https://daily.dev/posts/how-to-setup-flutter-firebase-with-multiple-flavors-using-the-flutterfire-cli-ye1rwts5c
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Setup Flutter & Firebase with Multiple Flavors using the FlutterFire CLI | daily.dev
og:description: Learn how to set up multiple Firebase environments for a Flutter app with different flavors using the FlutterFire CLI. The guide covers creating separate...
og:url: https://daily.dev/posts/how-to-setup-flutter-firebase-with-multiple-flavors-using-the-flutterfire-cli-ye1rwts5c
og:image: https://api.daily.dev/og/posts/Ye1Rwts5c.png
og:image:alt: How to Setup Flutter & Firebase with Multiple Flavors using the FlutterFire CLI
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Setup Flutter & Firebase with Multiple Flavors using the FlutterFire CLI

**[Collections](https://daily.dev/sources/collections)** · 3 min read · 13 upvotes · 1 comments

## Summary

Learn how to set up multiple Firebase environments for a Flutter app with different flavors using the FlutterFire CLI. The guide covers creating separate Firebase projects for each flavor, configuring these with shell scripts, and initializing Firebase during app startup on iOS, Android, and web platforms. This setup ensures security, efficiency, and organized configurations across various environments.

## Content

# How to Setup Flutter & Firebase with Multiple Flavors using the FlutterFire CLI

Setting up multiple Firebase environments for a Flutter app that supports multiple flavors can seem daunting, but with the right approach, you can streamline the process and ensure security and efficiency. This guide will walk you through creating separate Firebase projects for each flavor, configuring Firebase with shell scripts, and initializing Firebase during app startup on iOS, Android, and web platforms.

## Step 1: Create Firebase Projects for Each Flavor

To start, create separate Firebase projects for each flavor of your app. This isolation ensures that configurations and data don't overlap across different environments (e.g., development, staging, production).

1. Go to the [Firebase Console](https://console.firebase.google.com/).
2. Create a new project for each flavor.
3. Add your app to each Firebase project (iOS, Android, and web).
4. Download the `google-services.json` for Android and `GoogleService-Info.plist` for iOS for each project's flavor.

## Step 2: Configure Firebase with Shell Scripts

Next, set up shell scripts to help switch between different Firebase configurations for each flavor.

1. Create a `firebase_config.sh` script that copies the relevant `google-services.json` and `GoogleService-Info.plist` files into the correct locations based on the selected flavor.
2. Update your build process to call this script before building your Flutter app.

Example of a `firebase_config.sh` script:

```sh
#!/bin/bash

FLAVOR=$1

cp -f firebase/$FLAVOR/google-services.json android/app/
cp -f firebase/$FLAVOR/GoogleService-Info.plist ios/Runner/
```

## Step 3: Initialize Firebase During App Startup

Ensure that Firebase initializes correctly during app startup by configuring it based on the app flavor.

1. Create separate entry points for each flavor's configuration in Flutter. This approach, while requiring additional setup, will prevent bundling all config files in the final app, enhancing security.
2. Use the FlutterFire CLI to initialize Firebase in your Flutter app.
3. Use the `-t` flag to specify which flavor's config file to use during build and run commands.

Example of using the `-t` flag:

```sh
flutter run -t lib/main_flavor.dart
```

## Platforms: iOS, Android, and Web

### Android
In `android/app/build.gradle`, ensure that the correct `google-services.json` file is included using a build configuration.

### iOS
In Xcode, ensure that the correct `GoogleService-Info.plist` is bundled based on the build configuration.

### Web
For web platform support, make sure to import the correct Firebase config based on your environment.

## Benefits
This setup not only helps in avoiding common setup headaches but also ensures the security of different environment configurations and maintains a streamlined and efficient build process.

Following these steps, you'll set up a robust multi-flavor Firebase environment for your Flutter app, keeping your configurations organized and secure.

## Community discussion

Top comments from developers on daily.dev.

**@anushkapubudu** · 0 upvotes

> any method for flutter web??

---

Tags: [#android](https://daily.dev/tags/android), [#ios](https://daily.dev/tags/ios), [#flutter](https://daily.dev/tags/flutter), [#firebase](https://daily.dev/tags/firebase)

[View this post on daily.dev](https://daily.dev/posts/how-to-setup-flutter-firebase-with-multiple-flavors-using-the-flutterfire-cli-ye1rwts5c)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Setup Flutter & Firebase with Multiple Flavors using the FlutterFire CLI","url":"https://daily.dev/posts/how-to-setup-flutter-firebase-with-multiple-flavors-using-the-flutterfire-cli-ye1rwts5c","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-setup-flutter-firebase-with-multiple-flavors-using-the-flutterfire-cli-ye1rwts5c"},"datePublished":"2024-10-18T13:19:19.243Z","dateModified":"2024-10-18T13:19:34.329Z","description":"Learn how to set up multiple Firebase environments for a Flutter app with different flavors using the FlutterFire CLI. The guide covers creating separate...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e2ac4bb3fdb03c1968da9be55a85fe73?_a=AQAEuiZ","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e2ac4bb3fdb03c1968da9be55a85fe73?_a=AQAEuiZ","isAccessibleForFree":true,"articleSection":"Collections","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Collections","logo":"https://media.daily.dev/image/upload/s--fk_6ycEi--/f_auto,q_auto/v1780996001/logos/collections?_a=BAMAMiWQ0","url":"https://daily.dev/sources/collections"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/how-to-setup-flutter-firebase-with-multiple-flavors-using-the-flutterfire-cli-ye1rwts5c","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":13},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"android,ios,flutter,firebase","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Collections","item":"https://daily.dev/sources/collections"},{"@type":"ListItem","position":3,"name":"How to Setup Flutter & Firebase with Multiple Flavors using the FlutterFire CLI"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-to-setup-flutter-firebase-with-multiple-flavors-using-the-flutterfire-cli-ye1rwts5c","comment":[{"@type":"Comment","text":"any method for flutter web??","datePublished":"2025-01-03T17:46:23.186Z","url":"https://daily.dev/posts/Ye1Rwts5c#c-R0U2maIYW","author":{"@type":"Person","name":"Anushka Pubudu","url":"https://daily.dev/anushkapubudu","image":"https://avatars.githubusercontent.com/u/56330042?v=4"}}]}
```

