Closed
Description
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Core
Which platforms are affected?
Android
Description
The issue is the same happening in this issue, which is closed by proposing a workaround, but the root cause of the problem is not fixed.
After updating Gradle to the new declarative API, the issue started. In my specific case, I am using Flavors, each flavors has it's own google-services.json
. Before, when using the previous imperative Gradle API this issue was not happening.
Reproducing the issue
- Create a new Flutter project
- Create two flavors for example
dev
andprod
- Update settings.gradle to add
id "com.google.gms.google-services" version "4.4.0" apply false
- Update build.gradle to add
id "com.google.gms.google-services"
- Update the
main()
function to initialize Firebase.
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
Firebase Core version
2.31.0
Flutter Version
3.22.0
Relevant Log Output
I/ocode.devflavor( 5698): Compiler allocated 4579KB to compile void android.view.ViewRootImpl.performTraversals()
E/flutter ( 5698): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly., Exception, Cause: null, Stacktrace: java.lang.Exception: Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.
E/flutter ( 5698): at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin.lambda$optionsFromResource$4$io-flutter-plugins-firebase-core-FlutterFirebaseCorePlugin(FlutterFirebaseCorePlugin.java:207)
E/flutter ( 5698): at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin$$ExternalSyntheticLambda2.run(Unknown Source:4)
E/flutter ( 5698): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
E/flutter ( 5698): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
E/flutter ( 5698): at java.lang.Thread.run(Thread.java:1012)
E/flutter ( 5698): , null)
E/flutter ( 5698): #0 FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:242:7)
E/flutter ( 5698): <asynchronous suspension>
E/flutter ( 5698): #1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter ( 5698): <asynchronous suspension>
E/flutter ( 5698): #2 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter ( 5698): <asynchronous suspension>
E/flutter ( 5698): #3 main (package:firebase_options_example/main.dart:8:3)
E/flutter ( 5698): <asynchronous suspension>
E/flutter ( 5698):
### Flutter dependencies
<!--- Look below for instructions on how to share your Flutter Dependencies. --->
<details>
<summary>Expand <code>Flutter dependencies</code> snippet</summary>
<br>
```yaml
Dart SDK 3.4.0
Flutter SDK 3.22.0
firebase_options_example 1.0.0+1
dependencies:
- cupertino_icons 1.0.8
- firebase_core 2.31.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
dev dependencies:
- flutter_lints 4.0.0 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service]
transitive dependencies:
- async 2.11.0 [collection meta]
- boolean_selector 2.1.1 [source_span string_scanner]
- characters 1.3.0
- clock 1.1.1
- collection 1.18.0
- fake_async 1.3.1 [clock collection]
- firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.17.0 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- leak_tracker 10.0.4 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.3 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- lints 4.0.0
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.8.0 [collection]
- meta 1.12.0
- path 1.9.0
- plugin_platform_interface 2.1.8 [meta]
- sky_engine 0.0.99
- source_span 1.10.0 [collection path term_glyph]
- stack_trace 1.11.1 [path]
- stream_channel 2.1.2 [async]
- string_scanner 1.2.0 [source_span]
- term_glyph 1.2.1
- test_api 0.7.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- vector_math 2.1.4
- vm_service 14.2.1
- web 0.5.1
Additional context and comments
I created a minimal project that you can use to reproduce the problem. https://github.com/Yayo-Arellano/firebase_options_test
Just run the dev or prod flavor and you will see the crash:
flutter run --flavor dev
or
flutter run --flavor prod