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
- Go to the Firebase Console
- Click “Create a project” or “Add project”
- Enter your project name
- Follow the setup wizard to complete project creation
2. Install Required CLI Tools
3. Configure Flutter Project
- Add the following dependencies to your
pubspec.yaml
:
- Run flutter pub get:
4. Initialize Firebase in Your Project
- Run the FlutterFire configure command. Be sure to specify the flavour (dev/stg/prod):
-
-p
Sets the Firebase Project ID to use. -
-i
The bundle identifier of your iOS app, e.g. “com.example.app”. -
-a
The package name of your Android app, e.g. “com.example.app”. -
--out
Specifies the path & file name for the generated file.More information on flags may be found here.
- Select your created Firebase project
- This will automatically:
- Register your apps in Firebase console
- Download configuration files
- Add platform-specific configuration
5. Update Your Flutter Code
- Initialize Firebase in your main.dart:
Platform-Specific Setup
Android Setup
- Ensure your app’s
minSdkVersion
is at least 19 inandroid/app/build.gradle
:
iOS Setup
- Update your iOS deployment target in Xcode to at least iOS 11.0
- Add the GoogleService-Info.plist to your Runner target
- Update your iOS permissions in Info.plist if needed
Verification
To verify your Firebase setup:
- Run your app
- Check the console for successful Firebase initialization
- 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:
- Add Firebase Authentication
- Set up Cloud Firestore
- Implement Firebase Cloud Messaging
- Add Firebase Analytics
Additional Resources
Walkthrough Video
Follow along as the FLEX Team sets up Firebase and Crashlytics in a Storefront App.