E/flutter ( 6571): [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 ( 6571): at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin.lambda$optionsFromResource$4$io-flutter-plugins-firebase-core-FlutterFirebaseCorePlugin(FlutterFirebaseCorePlugin.java:207)
E/flutter ( 6571): at io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin$$ExternalSyntheticLambda2.run(Unknown Source:4)
E/flutter ( 6571): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
E/flutter ( 6571): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
E/flutter ( 6571): at java.lang.Thread.run(Thread.java:1012)
E/flutter ( 6571): , null)
E/flutter ( 6571): #0 FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:242:7)
E/flutter ( 6571): <asynchronous suspension>
E/flutter ( 6571): #1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter ( 6571): <asynchronous suspension>
E/flutter ( 6571): #2 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
Error throws right after calling await Firebase.initializeApp();
It's happening after removing imperative apply of Flutter's Gradle plugins which is deprecated. I.e. after migrate to the new, declarative apply issue started. Checked by creating new project also facing same issue.
App is building for iOS and Android not web.
Env: firebase_core: ^2.27.1
I found that after passing options
it's working:
await Firebase.initializeApp(
options: FirebaseOptions(
apiKey: 'key',
appId: 'id',
messagingSenderId: 'sendid',
projectId: 'myapp',
storageBucket: 'myapp-b9yt18.appspot.com',
)
);
Created new app, and configured it with CLI mode it will generate the options file for all platforms.
Just add google-services.json
won't be enough from flutter 3.19 it seems.
Once the files are generated your Firebase init code should look like this. Options are applied through CLI generated options file according to platform.
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform
);
However, your project distinguishes between test and production environments using the google-services.json
file, so you might need to manually configure it accordingly.
Don't forget to also check the iOS version, because this configuration doesn't work on iOS 15.4. So you'll need to distinguish between platforms as well.
apiKey = google-service.json [api_key]
appId = google-service.json [mobilesdk_app_id]
messagingSenderId = google-service.json [project_number]
projectId = google-service.json [project_id]
if (Platform.isAndroid) {
FirebaseOptions firebaseOptions;
if (environment == AppEnvironment.development) {
firebaseOptions = const FirebaseOptions(
apiKey: "DEV key",
appId: "DEV ID",
messagingSenderId: "DEV messagingSenderId",
projectId: "DEV projectId",
);
} else {
firebaseOptions = const FirebaseOptions(
apiKey: "PUB key",
appId: "PUB ID",
messagingSenderId: "PUB messagingSenderId",
projectId: "PUB projectId",
);
}