How to Setup Firebase in Flutter (Android & iOS Complete Step-by-Step Guide)

Learn how to set up Firebase in Flutter step-by-step for Android and iOS. Complete configuration guide with common errors, initialization, and production tips.

Introduction

Before using Firebase Authentication, Firestore, Storage, or any other Firebase service, you must properly configure Firebase inside your Flutter project.

Many beginners face errors during setup because of small configuration mistakes. In this complete guide, we will go step-by-step and configure Firebase for both Android and iOS properly.

By the end of this article, your Flutter project will be fully connected to Firebase and ready for production development.

Prerequisites

  • Flutter SDK installed
  • Android Studio or VS Code
  • Android SDK configured
  • Xcode installed (for iOS)
  • Google account

Step 1: Create Firebase Project

1. Go to Firebase Console.
2. Click “Add Project”.
3. Enter project name.
4. Disable Google Analytics if not needed.
5. Click Create Project.

Step 2: Add Android App to Firebase

Get Android Package Name

Open:

android/app/src/main/AndroidManifest.xml

Find:

package="com.example.myapp"

This is your Android package name.

Register App in Firebase

1. Click Android icon in Firebase project.
2. Enter package name.
3. Add app nickname (optional).
4. Click Register App.

Download google-services.json

Download the file and place it inside:

android/app/

Step 3: Configure Android Build Files

Edit android/build.gradle

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

Edit android/app/build.gradle

apply plugin: 'com.google.gms.google-services'

Make sure minSdkVersion is at least 21.

Step 4: Add iOS App to Firebase

Get iOS Bundle Identifier

Open:

ios/Runner.xcodeproj

Find Bundle Identifier inside Runner target.

Register iOS App in Firebase

1. Click iOS icon in Firebase console.
2. Enter Bundle ID.
3. Download GoogleService-Info.plist.

Add File to Xcode

Open ios folder in Xcode. Drag GoogleService-Info.plist into Runner project. Make sure it is added to target.

Step 5: Add Firebase Packages

Open pubspec.yaml and add:

dependencies:
  firebase_core: latest_version

Then run:

flutter pub get

Step 6: Initialize Firebase in main.dart

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

If initialization is missing, Firebase services will not work.

Step 7: Run the App

flutter run

If everything is configured correctly, the app should run without Firebase errors.

Common Setup Errors & Solutions

1. Firebase.initializeApp() not called

Solution: Ensure async main method and call initializeApp().

2. google-services.json missing

Solution: Place file inside android/app folder.

3. iOS Build Fails

Run:

cd ios
pod install

4. SHA-1 Missing

For Google sign-in, add SHA-1 key inside Firebase console.

Using FlutterFire CLI (Recommended Modern Way)

Install FlutterFire CLI:

dart pub global activate flutterfire_cli

Configure project:

flutterfire configure

This automatically generates firebase_options.dart file.

Initialize Using Generated Options

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

This is the recommended production setup.

Production Setup Tips

  • Use different Firebase projects for development and production
  • Enable App Check
  • Configure security rules early
  • Do not expose sensitive API keys publicly

How to Verify Firebase Connection

After running the app:

  • Go to Firebase Console
  • Check if your app is connected
  • Check Analytics debug view

Conclusion

Firebase setup is the foundation of backend integration in Flutter. Once configured correctly, you can start using Authentication, Firestore, Storage, and other services smoothly.

In the next article, we will deeply explore: Firebase Authentication (Email & Password Complete Guide).

Share

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0