Complete guide for setting up Firebase Crashlytics and Analytics in the Cambridge Beer Festival app.
- Prerequisites
- Step 1: Create Firebase Project
- Step 2: Register Your Apps
- Step 3: Download Configuration Files
- Step 4: Install Firebase CLI
- Step 5: Configure FlutterFire
- Step 6: Update Platform-Specific Configuration
- Step 7: Install Dependencies
- Step 8: Test the Integration
- Troubleshooting
- Google account
- Flutter development environment set up
- Firebase CLI installed (covered in Step 4)
- Go to the Firebase Console
- Click "Add project" or "Create a project"
- Enter project name:
cambridge-beer-festival(or your preferred name) - Google Analytics: Enable (recommended) - you can use existing account or create new
- Click "Create project" and wait for setup to complete
- Click "Continue" to enter your project
You need to register separate apps for each platform you're targeting.
- In Firebase Console, click the Android icon to add an Android app
- Android package name:
ralcock.cbf⚠️ Important: This must match your app's package ID exactly- This is the package name used in the Play Store listing
- App nickname (optional): "Cambridge Beer Festival Android"
- Debug signing certificate SHA-1 (optional, but recommended for testing):
# Get your debug certificate SHA-1 keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore # Default password is usually: android
- Click "Register app"
- Download
google-services.json(you'll need this file!) - Click "Next" and "Continue to console"
- In Firebase Console, click the iOS icon to add an iOS app
- iOS bundle ID:
ralcock.cbf(or your chosen bundle ID)⚠️ Important: This should match your iOS app's bundle identifier
- App nickname (optional): "Cambridge Beer Festival iOS"
- Click "Register app"
- Download
GoogleService-Info.plist(you'll need this file!) - Click "Next" and "Continue to console"
- In Firebase Console, click the Web icon to add a web app
- App nickname: "Cambridge Beer Festival Web"
- Firebase Hosting (optional): Check if you want to use Firebase Hosting
- Click "Register app"
- Copy the Firebase configuration (you'll need this for
firebase_options.dart) - Click "Continue to console"
File: google-services.json
Location: android/app/google-services.json
cambridge-beer-festival-app/
├── android/
│ ├── app/
│ │ ├── google-services.json ← Place here
│ │ └── build.gradle
│ └── build.gradle
Important: This file contains your Firebase project credentials. DO NOT commit it to public repositories unless it's a public/demo project.
File: GoogleService-Info.plist
Location: ios/Runner/GoogleService-Info.plist
cambridge-beer-festival-app/
├── ios/
│ ├── Runner/
│ │ ├── GoogleService-Info.plist ← Place here
│ │ ├── Info.plist
│ │ └── Runner.xcodeproj
Note: You also need to add this file to Xcode:
- Open
ios/Runner.xcworkspacein Xcode - Right-click on
Runnerfolder in project navigator - Select "Add Files to Runner..."
- Select
GoogleService-Info.plist - Ensure "Copy items if needed" is checked
- Click "Add"
The Firebase CLI and FlutterFire CLI are needed to generate platform configuration.
# Using npm (recommended)
npm install -g firebase-tools
# Or using curl (macOS/Linux)
curl -sL https://firebase.tools | bash
# Verify installation
firebase --versionfirebase loginThis will open a browser window for authentication.
FlutterFire CLI generates the firebase_options.dart file automatically based on your Firebase project.
dart pub global activate flutterfire_cliFrom the root of your Flutter project:
# Configure Firebase for your project
flutterfire configure
# Or specify project explicitly
flutterfire configure --project=cambridge-beer-festivalThis command will:
- Detect your Firebase projects
- Let you select which project to use
- Detect platforms in your Flutter project
- Generate
lib/firebase_options.dartautomatically
Select platforms when prompted:
- ✅ Android
- ✅ iOS
- ✅ Web (if you're building for web)
The command creates: lib/firebase_options.dart
// This file is auto-generated - DO NOT EDIT MANUALLY
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb, TargetPlatform;
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
// ... other platforms
}
}
static const FirebaseOptions android = FirebaseOptions(
apiKey: 'YOUR_ANDROID_API_KEY',
appId: 'YOUR_ANDROID_APP_ID',
// ...
);
// ... iOS and web configurations
}File: android/build.gradle
Add Google services classpath:
buildscript {
dependencies {
// ... existing dependencies
classpath 'com.google.gms:google-services:4.4.2' // Add this line
classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2' // Add this line
}
}File: android/app/build.gradle
Add plugins at the bottom of the file:
// ... rest of your build.gradle
apply plugin: 'com.google.gms.google-services' // Add this line
apply plugin: 'com.google.firebase.crashlytics' // Add this lineAlso ensure minSdkVersion is at least 21:
android {
defaultConfig {
minSdkVersion 21 // Ensure this is at least 21
// ... other config
}
}File: ios/Podfile
Ensure platform is iOS 13.0 or higher:
platform :ios, '13.0' # Ensure this is at least 13.0cd ios
pod install
cd ..For better crash reports with dSYM files:
- Open
ios/Runner.xcworkspacein Xcode - Select your Runner target
- Go to Build Phases
- Click + → New Run Script Phase
- Add this script:
"${PODS_ROOT}/FirebaseCrashlytics/run"- Ensure it runs after "Compile Sources" phase
From the project root:
flutter pub getThis installs the Firebase packages already added to pubspec.yaml:
firebase_corefirebase_crashlyticsfirebase_analytics
Check that packages are listed in pubspec.lock without errors.
# Build and run on Android device/emulator
flutter run
# Check logcat for Firebase initialization
adb logcat | grep -i firebase# Build and run on iOS device/simulator
flutter run
# Check console logs for Firebase initialization
# (View in Xcode console or device logs)To test crash reporting:
- Add a test crash button temporarily:
ElevatedButton(
onPressed: () {
FirebaseCrashlytics.instance.crash(); // Force crash
},
child: Text('Test Crash'),
)- Run the app, tap the button
- Restart the app (Crashlytics sends reports on next launch)
- Check Firebase Console → Crashlytics (may take 5-10 minutes to appear)
Check Firebase Console → Analytics → Events to see events being logged:
app_openfestival_selectedfavorite_added- etc.
Note: Analytics events may take several hours to appear in the console.
After setup, your project should have these Firebase-related files:
cambridge-beer-festival-app/
├── lib/
│ ├── firebase_options.dart ← Auto-generated by flutterfire
│ ├── main.dart ← Firebase initialization added
│ └── services/
│ └── analytics_service.dart ← Analytics & Crashlytics wrapper
│
├── android/
│ ├── app/
│ │ ├── google-services.json ← Downloaded from Firebase Console
│ │ └── build.gradle ← Updated with Firebase plugins
│ └── build.gradle ← Updated with classpath
│
├── ios/
│ ├── Runner/
│ │ ├── GoogleService-Info.plist ← Downloaded from Firebase Console
│ │ └── Info.plist
│ └── Podfile ← Ensure iOS 13.0+
│
└── pubspec.yaml ← Firebase dependencies added
Solution: Ensure Firebase.initializeApp() is called in main() before runApp().
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const BeerFestivalApp());
}Solution: Place the file in android/app/ (not android/)
Solution:
- Place the file in
ios/Runner/ - Add it to Xcode project (right-click Runner → Add Files)
Solutions:
- Ensure
apply plugin: 'com.google.gms.google-services'is at the bottom ofandroid/app/build.gradle - Run
flutter clean && flutter pub get - Verify
google-services.jsonis in correct location
Solutions:
cd ios
rm -rf Pods Podfile.lock
pod install --repo-update
cd ..
flutter clean
flutter pub getSolutions:
- Ensure app is restarted after crash (reports sent on next launch)
- Check that
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true)is set - Wait 5-10 minutes for crashes to appear in console
- For iOS, ensure dSYMs are uploaded (automatic in debug builds)
Solution: Run flutterfire configure from project root
Reasons:
- Analytics has a delay (can be several hours in debug mode)
- Debug events are filtered by default in Firebase Console
- Enable debug view:
# Android adb shell setprop debug.firebase.analytics.app ralcock.cbf # iOS - run with argument: -FIRAnalyticsDebugEnabled
✅ Safe to commit:
lib/firebase_options.dart(placeholder template)android/app/build.gradle(configuration files)android/build.gradleios/Podfile
.gitignore):
android/app/google-services.json(contains API keys)ios/Runner/GoogleService-Info.plist(contains API keys)- Actual
lib/firebase_options.dartafter runningflutterfire configure
For GitHub Actions and CI/CD builds, Firebase configuration is provided via GitHub Secrets.
See GITHUB_SECRETS.md for complete CI/CD setup instructions.
The workflow automatically creates the Firebase config files from secrets during builds:
GOOGLE_SERVICES_JSON→android/app/google-services.jsonFIREBASE_OPTIONS_DART→lib/firebase_options.dart
This allows builds to work in CI without committing sensitive files to version control.
The code changes for Firebase integration are already complete:
✅ Dependencies added to pubspec.yaml
✅ Firebase initialization in lib/main.dart
✅ Crashlytics error handling in BeerProvider
✅ Analytics service created (lib/services/analytics_service.dart)
✅ Analytics events tracked throughout the app
What you need to do:
- Create Firebase project
- Download and place configuration files
- Run
flutterfire configure - Update Android/iOS build files
- Test the integration
Once you complete these steps, Firebase Crashlytics and Analytics will be fully operational!