Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_core]: When using flavors in Android <Unhandled Exception: PlatformException(java.lang.Exception: Failed to load FirebaseOptions> #12802

Open
1 task done
Yayo-Arellano opened this issue May 19, 2024 · 3 comments
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: android Issues / PRs which are specifically for Android. plugin: core Stale Issue with no recent activity type: bug Something isn't working

Comments

@Yayo-Arellano
Copy link

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

  1. Create a new Flutter project
  2. Create two flavors for example dev and prod
  3. Update settings.gradle to add id "com.google.gms.google-services" version "4.4.0" apply false
  4. Update build.gradle to add id "com.google.gms.google-services"
  5. 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

@Yayo-Arellano Yayo-Arellano added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels May 19, 2024
@Yayo-Arellano
Copy link
Author

Probably the problem is in the latest versions of google services because if I downgrade the version the app works.

id "com.google.gms.google-services" version "4.3.8" apply false

@TarekkMA TarekkMA added plugin: core platform: android Issues / PRs which are specifically for Android. labels May 20, 2024
@TarekkMA
Copy link
Contributor

Hello @Yayo-Arellano thank you for reporting this issue. It was reported #12760 (comment) that downgrading to v4.3.X seemed to fix the issue. It might be an issue to be escalated to the firebase-android-sdk.

@TarekkMA TarekkMA added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels May 20, 2024
@google-oss-bot google-oss-bot added the Stale Issue with no recent activity label May 29, 2024
@google-oss-bot
Copy link

Hey @Yayo-Arellano. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: android Issues / PRs which are specifically for Android. plugin: core Stale Issue with no recent activity type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants