How to Disconnect Firebase from an Existing Flutter Project
Firebase integration provides powerful features, but there might be situations where you need to disconnect it from your existing Flutter project. In this guide, I will walk you through the process step-by-step, ensuring that all Firebase-related configurations are removed.
Step 1: Remove Firebase SDKs from Your Flutter Project
The first thing you need to do is remove any Firebase-related SDKs from your pubspec.yaml
file.
How to Do It:
# Open your pubspec.yaml file and remove the following dependencies: dependencies: firebase_core: # remove this firebase_auth: # remove this cloud_firestore: # remove this # And any other Firebase packages
After removing the dependencies, run:
flutter pub get
This will update your dependencies and remove the Firebase SDKs from your project.
Step 2: Remove Firebase Configuration Files
For Android:
- Delete the
google-services.json
file from yourandroid/app
directory. - Open
android/build.gradle
and remove the Firebase dependency:
# Look for the following line in build.gradle (Project Level): classpath 'com.google.gms:google-services:...'
- Open
android/app/build.gradle
and remove the Google services plugin:
apply plugin: 'com.google.gms.google-services'
For iOS:
- Delete the
GoogleService-Info.plist
file from yourios/Runner
directory. - Open
ios/Runner.xcworkspace
in Xcode and ensure there’s no reference to this file. - In your
ios/Podfile
, remove any Firebase-related pods, such as:
pod 'Firebase/Core' pod 'Firebase/Auth' pod 'Firebase/Firestore'
Run the following command in the iOS directory:
pod install
Step 3: Clean the Project
After removing the Firebase configurations, clean your project:
flutter clean
This will clear the cache and ensure that no Firebase-related files or settings linger.
Step 4: Remove Firebase Initialization Code
Look through your Dart files for any Firebase initialization code, and remove it. For example:
await Firebase.initializeApp();
Also, remove any Firebase-related services (authentication, Firestore, etc.) that you may have been using.
Step 5: Remove Firebase Analytics (If Applicable)
If you were using Firebase Analytics, ensure you remove any code or configuration related to it.
- For Android: Check for Firebase Analytics references in the
AndroidManifest.xml
. - For iOS: Ensure that Xcode does not include Firebase Analytics settings.
Step 6: Delete Firebase Build Configurations (Optional)
Some Firebase-related configurations might still remain. It’s good to clean these up:
- In Android, check the
proguard-rules.pro
file for Firebase rules and remove them. - In iOS, double-check your project settings (especially under Capabilities) to ensure Firebase is completely disconnected.
Step 7: Clear Cache (Optional but Recommended)
Clearing the build cache ensures a fresh build:
flutter clean
Alternatively, you can manually delete the .dart_tool
, build
, and ios/Pods
directories and rebuild the project.
Step 8: (Optional) Remove the Firebase Project from Firebase Console
If you no longer need the Firebase project, you can remove it from your Firebase Console.
Important: This action will delete all Firebase services like Firestore, Authentication, and Storage associated with the project, so be cautious!
Step 9: Double-Check for Firebase Dependencies
Finally, search your project for any leftover Firebase references, such as:
# In your project, run a search for 'firebase_' to ensure no remnants are left.
Conclusion
Disconnecting Firebase from a Flutter project might seem daunting, but by following these steps, you can ensure that Firebase is fully removed from your app. Whether it's the removal of SDKs, configuration files, or lingering initialization code, each step plays a critical role in making your project Firebase-free!
Tip: Always make a backup of your project before removing services like Firebase.
Summary of Steps:
- Remove Firebase SDKs from
pubspec.yaml
. - Delete Firebase configuration files (
google-services.json
andGoogleService-Info.plist
). - Clean the project using
flutter clean
. - Remove Firebase initialization and related code from Dart files.
- Remove Firebase Analytics (if used).
- Clean Firebase build configurations in Android/iOS.
- Clear the cache for a fresh build.
- Optionally, remove the Firebase project from Firebase Console.
- Double-check for remaining Firebase dependencies.