Closed Cyrille-Dakhlia closed 3 days ago
See documentation for what is valid in terms of placing your google-services.json
file: https://developers.google.com/android/guides/google-services-plugin#adding_the_json_file
If any of the directories containing the google-services.json file are not a build type or flavor, you're going to have a problem.
I imagine looking at this that firebase & flavors are unnecessary directories: android/app/firebase/flavors/staging/google-services.json
This isn't something we have control over, it is just how the google services plugin works.
Is there an existing issue for this?
CLI Version
1.0.0
Firebase Tools version
13.11.2
Flutter Doctor Output
flutter doctor -v [✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale en-GB) • Flutter version 3.22.2 on channel stable at /Users/cyrilledakhlia/Development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 761747bfc5 (13 days ago), 2024-06-05 22:15:13 +0200 • Engine revision edd8546116 • Dart version 3.4.3 • DevTools version 2.34.3
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/cyrilledakhlia/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2
[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
[✓] VS Code (version 1.90.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.90.0
[✓] Connected device (4 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 14 (API 34) (emulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.5 23F79 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.61
[✓] Network resources • All expected network resources are available.
• No issues found!
Description
TL;DR: After running
flutterfire configure
with this parameter and its value--android-out=android/app/firebase/flavors/staging/google-services.json
, running the staging version of my app on an Android emulator gives me the following error:-> The Gradle task does not search the
google-services.json
file where I specified itDETAILED DESCRIPTION:
staging
andproduction
that are working well for some time for both Android and iOSflutterfire
command:main.dart
file to load the appropriateFirebaseOptions
:import 'package:flutter/services.dart'; import 'firebase/firebase_options_production.dart' as production; import 'firebase/firebase_options_staging.dart' as staging; import 'package:firebase_core/firebase_core.dart';
enum Flavor { production(envFilePath: 'env/production.env'), staging(envFilePath: 'env/staging.env');
final String envFilePath;
const Flavor({required this.envFilePath}); }
Flavor getFlavor() => switch (appFlavor) { 'production' => Flavor.production, 'staging' => Flavor.staging, _ => throw UnsupportedError( 'Invalid flavor: "$appFlavor". Please specify one of the following flavors: "production", "staging" (
flutter run --flavor staging
).'), };Future initializeFirebaseApp() async {
final firebaseOptions = switch (getFlavor()) {
Flavor.production => production.DefaultFirebaseOptions.currentPlatform,
Flavor.staging => staging.DefaultFirebaseOptions.currentPlatform,
};
await Firebase.initializeApp(options: firebaseOptions);
}
So I can see that the
--android-out=android/app/firebase/flavors/staging/google-services.json
parameter I specified when running theflutterfire command
was taken into account as it has it is mentioned in thefirebase.json
file.When I try to run the staging version of my app on an Android emulator, it fails and I get the following error printed:
What went wrong: Execution failed for task ':app:processStagingDebugGoogleServices'.
Try:
BUILD FAILED in 3s Error: Gradle task assembleStagingDebug failed with exit code 1
Exited (1).
main.dart
and add aflavor_config.dart
file like so:import 'package:flutter/services.dart'; import 'firebase/firebase_options_production.dart' as production; import 'firebase/firebase_options_staging.dart' as staging; import 'package:firebase_core/firebase_core.dart';
enum Flavor { production, staging }
Flavor getFlavor() => switch (appFlavor) { // This
appFlavor
variable comes frompackage:flutter/services.dart
'production' => Flavor.production, 'staging' => Flavor.staging, _ => throw UnsupportedError( 'Invalid flavor: "$appFlavor". Please specify one of the following flavors: "production", "staging" (flutter run --flavor staging
).'), };Future initializeFirebaseApp() async {
final firebaseOptions = switch (getFlavor()) {
Flavor.production => production.DefaultFirebaseOptions.currentPlatform,
Flavor.staging => staging.DefaultFirebaseOptions.currentPlatform,
};
await Firebase.initializeApp(options: firebaseOptions);
}
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:processStagingDebugGoogleServices'.
Try:
BUILD FAILED in 3s Error: Gradle task assembleStagingDebug failed with exit code 1
Exited (1).
android/app/firebase/flavors/staging/google-services.json
Execution failed for task ':app:processStagingDebugGoogleServices'.
Screenshots
No response
Additional context and comments
No response