Skip to content

Setting up Firebase

Prerequisites

  • Flutter SDK installed and configured
  • A Google account
  • Flutter project created and running
  • Firebase CLI installed

Installation Steps

1. Create a Firebase Project

  1. Go to the Firebase Console
  2. Click “Create a project” or “Add project”
  3. Enter your project name
  4. Follow the setup wizard to complete project creation

2. Install Required CLI Tools

Terminal window
# Install the FlutterFire CLI
dart pub global activate flutterfire_cli

3. Configure Flutter Project

  1. Add the following dependencies to your pubspec.yaml:
dependencies:
firebase_core: ^latest_version
# Add other Firebase packages as needed:
# firebase_auth: ^latest_version
# cloud_firestore: ^latest_version
# firebase_storage: ^latest_version
  1. Run flutter pub get:
Terminal window
flutter pub get

4. Initialize Firebase in Your Project

  1. Run the FlutterFire configure command:
Terminal window
flutterfire configure
  1. Select your created Firebase project
  2. This will automatically:
    • Register your apps in Firebase console
    • Download configuration files
    • Add platform-specific configuration

5. Update Your Flutter Code

  1. Initialize Firebase in your main.dart:
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}

Platform-Specific Setup

Android Setup

  1. Ensure your app’s minSdkVersion is at least 19 in android/app/build.gradle:
android {
defaultConfig {
minSdkVersion 19
// ...
}
}

iOS Setup

  1. Update your iOS deployment target in Xcode to at least iOS 11.0
  2. Add the GoogleService-Info.plist to your Runner target
  3. Update your iOS permissions in Info.plist if needed

Verification

To verify your Firebase setup:

  1. Run your app
  2. Check the console for successful Firebase initialization
  3. Try implementing a basic Firebase feature (like Analytics)

Common Issues and Troubleshooting

Android Issues

  • Gradle sync failures: Check your project-level build.gradle for Google services plugin
  • Missing google-services.json: Ensure the file is in android/app/

iOS Issues

  • Missing GoogleService-Info.plist
  • Incorrect Bundle ID
  • CocoaPods installation issues

Next Steps

After successful installation, you can:

  1. Add Firebase Authentication
  2. Set up Cloud Firestore
  3. Implement Firebase Cloud Messaging
  4. Add Firebase Analytics

Additional Resources

Walkthrough Video

Follow along as the FLEX Team sets up Firebase and Crashlytics in a Storefront App.

Setting up Firebase