firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.58k stars 3.94k forks source link

Getting platform exception [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null) E/flutter (28941): #0 #12393

Closed mrazamerchant closed 5 months ago

mrazamerchant commented 6 months ago

Bug report

Describe the bug

i have a project where i use to work on flutter 3.16.0 and its working fine but when i migrated my flutter from 3.16.0 to current latest version 3.19.1 and i got firebase exception.

The Error i got on debug console :

D/FlutterGeolocator( 3804): Flutter engine connected. Connected engine count 1
E/flutter ( 3804): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null)
E/flutter ( 3804): #0 FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
E/flutter ( 3804):
E/flutter ( 3804): https://github.com/firebase/flutterfire/pull/1 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)

I used official article to migrate flutter to 3.19.1. https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

darshankawar commented 6 months ago

@mrazamerchant Can you provide us a runnable code sample along with flutter dependencies you are using and what changes you made that is leading to this error ?

mrazamerchant commented 6 months ago

@mrazamerchant Can you provide us a runnable code sample along with flutter dependencies you are using and what changes you made that is leading to this error ?

i have a project where i use to work on flutter 3.16.0 and its working fine but when i migrated my flutter from 3.16.0 to current latest version 3.19.1 and i got firebase exception.

These are my gradle configuration images: https://github.com/firebase/flutterfire/assets/140117432/4a118bcb-4ca8-4c82-861a-88f55607e9d0 https://github.com/firebase/flutterfire/assets/140117432/8778d6ff-c60c-4aa0-80d9-9a8c638a4e57 https://github.com/firebase/flutterfire/assets/140117432/704b77b9-5338-4ce0-bf81-61a402500461 https://github.com/firebase/flutterfire/assets/140117432/c1853a23-dd91-49cc-8201-07dfbc6a94c3

I used official article to migrate flutter to 3.19.1. https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

Remember my project running fine on 3.16.0 Please provide quick solution as i need to upgrade my project thanks in advance.

darshankawar commented 6 months ago

@mrazamerchant It might not necessarily be a flutterfire issue, but could be ripple effects of the migration. See this original flutter issue that implemented the changes and https://github.com/flutter/flutter/issues/135392#issuecomment-1872529798 for reference.

Also would like to confirm if you carefully followed all the steps to properly migrate, as it requires some changes to be at specific positions in respective files. Also, if you could also try to check if the similar error occurs without using flutterfire plugins or if this is specific to flutterfire or not.

mrazamerchant commented 6 months ago

@mrazamerchant It might not necessarily be a flutterfire issue, but could be ripple effects of the migration. See this original flutter issue that implemented the changes and flutter/flutter#135392 (comment) for reference.

Also would like to confirm if you carefully followed all the steps to properly migrate, as it requires some changes to be at specific positions in respective files. Also, if you could also try to check if the similar error occurs without using flutterfire plugins or if this is specific to flutterfire or not.

i have follow all the necessary steps to migrate and if you see my images of configuration if you would find its same as the officially document suggest.Now i have configure firebase manually with out cli and its working on flutter 3.16.0.

stuartmorgan commented 6 months ago

Regardless of what the underlying issue that's causing option creation to fail, this code clearly violates the protocol definition, since it is explicitly returning null for a Pigeon method that was declared as non-nullable.

mrazamerchant commented 6 months ago

when i posted the issue in the flutter community this is what i got: This is firebase_core code that is returning an invalid value according to their own protocol definition; you'd need to report this to the plugin's developers to investigate. If they determine as part of that investigation that the reason for the failure is a bug in 3.19 they can file an issue here with specifics about what the Flutter aspect of this is.

JobiJoba commented 6 months ago

I've the same issue and did the same as original post.

kamami commented 6 months ago

I also have this issue and did the migration.

Lyokone commented 6 months ago

Hello @mrazamerchant, I've tried to migrate the example app without any issues. It looks like this issue happens because we cannot initialize without the values.xml. Since it's not the most common way to initialize Firebase on Android, can you share how you are running Firebase.initializeApp?

kamami commented 6 months ago

Nevermind, I just managed to get it working.

Chappie74 commented 6 months ago

@kamami can you please share how?

JobiJoba commented 6 months ago

Hello @mrazamerchant, I've tried to migrate the example app without any issues. It looks like this issue happens because we cannot initialize without the values.xml. Since it's not the most common way to initialize Firebase on Android, can you share how you are running Firebase.initializeApp?

I don't have that values.xml in my app.

I've created a new flutter app - use flutterfire to configure and it does not have a values.xml neither.

In dart I initialize this way : await Firebase.initializeApp();

Lyokone commented 6 months ago

@JobiJoba, did you follow those instructions? You are supposed to do

await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);
mrazamerchant commented 6 months ago

Hello @mrazamerchant, I've tried to migrate the example app without any issues. It looks like this issue happens because we cannot initialize without the values.xml. Since it's not the most common way to initialize Firebase on Android, can you share how you are running Firebase.initializeApp?

That is how i initialize firebase i didn't use cli approach i just configured firebase manually.

await Firebase.initializeApp(); FirebaseMessaging.onBackgroundMessage(myBackgroundMessageHandler); tz.initializeTimeZones(); await FlutterDownloader.initialize( debug: true // optional: set false to disable printing logs to console. );

FirebaseAnalytics analytics = FirebaseAnalytics.instance; analytics.logEvent(name: 'TestEvent', parameters: {'one': 'testSuccessful'}); and this is one is working fine in flutter 3.16.0 the issue arrived in 3.19.1 so it means issue is with flutter 3.19.1 and also if i dont use firebase with flutter 3.19.1 then its working.

kamami commented 6 months ago

@kamami can you please share how?

To be honest I just followed the migration guide. It fixed in particular this issue, which was closed as a duplicate of this issue described here. https://github.com/firebase/flutterfire/issues/12379 I am running on flutter 3.19.0 with the latest Firestore Package version

carman247 commented 6 months ago

Error inside of runZonedGuarded

E/flutter (25121): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
E/flutter (25121): #0      MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:193:5)
E/flutter (25121): #1      Firebase.app (package:firebase_core/src/firebase.dart:56:41)
E/flutter (25121): #2      FirebaseCrashlytics.instance (package:firebase_crashlytics/src/firebase_crashlytics.dart:33:55)
E/flutter (25121): #3      main.<anonymous closure> (package:bt/main.dart:39:25)
E/flutter (25121): #4      _RootZone.runBinary (dart:async/zone.dart:1666:54)
E/flutter (25121): #5      runZonedGuarded.<anonymous closure> (dart:async/zone.dart:1776:18)
E/flutter (25121): #6      _Zone._processUncaughtError (dart:async/zone.dart:1081:14)
E/flutter (25121): #7      _CustomZone.handleUncaughtError (dart:async/zone.dart:1285:5)
E/flutter (25121): #8      Future._propagateToListeners (dart:async/future_impl.dart:754:16)
E/flutter (25121): #9      Future._completeError (dart:async/future_impl.dart:649:5)
E/flutter (25121): #10     _rootRunBinary (dart:async/zone.dart:1423:47)
E/flutter (25121): #11     _CustomZone.runBinary (dart:async/zone.dart:1315:19)
E/flutter (25121): #12     _FutureListener.handleError (dart:async/future_impl.dart:171:22)
E/flutter (25121): #13     Future._propagateToListeners.handleError (dart:async/future_impl.dart:852:47)
E/flutter (25121): #14     Future._propagateToListeners (dart:async/future_impl.dart:873:13)
E/flutter (25121): #15     Future._completeError (dart:async/future_impl.dart:649:5)
E/flutter (25121): #16     _rootRunBinary (dart:async/zone.dart:1423:47)
E/flutter (25121): #17     _CustomZone.runBinary (dart:async/zone.dart:1315:19)
E/flutter (25121): #18     _FutureListener.handleError (dart:async/future_impl.dart:171:22)
E/flutter (25121): #19     Future._propagateToListeners.handleError (dart:async/future_impl.dart:852:47)
E/flutter (25121): #20     Future._propagateToListeners (dart:async/future_impl.dart:873:13)
E/flutter (25121): #21     Future._completeError (dart:async/future_impl.dart:649:5)
E/flutter (25121): #22     _rootRunBinary (dart:async/zone.dart:1423:47)
E/flutter (25121): #23     _CustomZone.runBinary (dart:async/zone.dart:1315:19)
E/flutter (25121): #24     _FutureListener.handleError (dart:async/future_impl.dart:171:22)

Error inside of main

Connecting to VM Service at ws://127.0.0.1:59359/o9ni1p4hA3U=/ws
E/flutter (23171): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
E/flutter (23171): #0      FirebaseCoreHostApi.initializeCore (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:210:7)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): #1      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:29:44)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): #2      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:73:7)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): #3      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): #4      main (package:bt/main.dart:25:3)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): 
I/rple.btpinphon(23171): ProcessProfilingInfo new_methods=1237 is saved saved_to_disk=1 resolve_classes_delay=8000

I'm also getting this error on one Android device but not another.

No idea what's going on. I've ran flutterfire configure like I normally do with all projects. Everything is exactly the same as the others.

What's really strange is it works on my Samsung Tab A8 but not my Xiaomi Mi 9T.

Any suggestions would be greatly appreciated.

void main() {
  runZonedGuarded(() async {
    WidgetsFlutterBinding.ensureInitialized();

    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );

    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);

    FlutterError.onError = (details) {
      FirebaseCrashlytics.instance.recordFlutterFatalError(details);
    };

    PlatformDispatcher.instance.onError = (error, stack) {
      FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
      return true;
    };

    runApp(const MyApp());
  }, (error, stack) {
    FirebaseCrashlytics.instance.recordError(error, stack);
  });
}
environment:
  sdk: '>=3.1.0 <4.0.0'

  firebase_core: ^2.24.2
  firebase_crashlytics: ^3.4.9

What's really strange is that on the Samsung A8 Tablet I'm able to run the app but I've just noticed this error in the console:

W/Firebase-Installations(10727): Error when communicating with the Firebase Installations server API. HTTP response: [400 Bad Request: {
W/Firebase-Installations(10727):   "error": {
W/Firebase-Installations(10727):     "code": 400,
W/Firebase-Installations(10727):     "message": "API key not valid. Please pass a valid API key.",
W/Firebase-Installations(10727):     "status": "INVALID_ARGUMENT",
W/Firebase-Installations(10727):     "details": [
W/Firebase-Installations(10727):       {
W/Firebase-Installations(10727):         "@type": "type.googleapis.com/google.rpc.ErrorInfo",
W/Firebase-Installations(10727):         "reason": "API_KEY_INVALID",
W/Firebase-Installations(10727):         "domain": "googleapis.com",
W/Firebase-Installations(10727):         "metadata": {
W/Firebase-Installations(10727):           "service": "firebaseinstallations.googleapis.com"
W/Firebase-Installations(10727):         }
W/Firebase-Installations(10727):       }
W/Firebase-Installations(10727):     ]
W/Firebase-Installations(10727):   }
W/Firebase-Installations(10727): }
W/Firebase-Installations(10727): ]
W/Firebase-Installations(10727): Firebase options used while communicating with Firebase server APIs: AIzaSyCVgdp2oYid_v_le1ZCPT4O8ABmPrltzs4, bt-pin-phone, 1:124725696474:android:ab44c7c69b82c25fc612e3
E/Firebase-Installations(10727): Firebase Installations can not communicate with Firebase server APIs due to invalid configuration. Please update your Firebase initialization process and set valid Firebase options (API key, Project ID, Application ID) when initializing Firebase.

I've checked the firebase_options.dart file and can see there is definitely an API key present in the options. Maybe it's not getting sent with the rest of the info for some reason?

Chappie74 commented 6 months ago

@JobiJoba, did you follow those instructions? You are supposed to do

await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

This worked for me. At first I wasn't using the Firebase CLI and was trying to use the google-services.json method, which wasn't working.

JobiJoba commented 6 months ago

@JobiJoba, did you follow those instructions? You are supposed to do

await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

It solved the issue thanks - Why it wasn't there ... This code has travelled multiple era of Firebase :)

carman247 commented 5 months ago

Error inside of runZonedGuarded

E/flutter (25121): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
E/flutter (25121): #0      MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:193:5)
E/flutter (25121): #1      Firebase.app (package:firebase_core/src/firebase.dart:56:41)
E/flutter (25121): #2      FirebaseCrashlytics.instance (package:firebase_crashlytics/src/firebase_crashlytics.dart:33:55)
E/flutter (25121): #3      main.<anonymous closure> (package:bt/main.dart:39:25)
E/flutter (25121): #4      _RootZone.runBinary (dart:async/zone.dart:1666:54)
E/flutter (25121): #5      runZonedGuarded.<anonymous closure> (dart:async/zone.dart:1776:18)
E/flutter (25121): #6      _Zone._processUncaughtError (dart:async/zone.dart:1081:14)
E/flutter (25121): #7      _CustomZone.handleUncaughtError (dart:async/zone.dart:1285:5)
E/flutter (25121): #8      Future._propagateToListeners (dart:async/future_impl.dart:754:16)
E/flutter (25121): #9      Future._completeError (dart:async/future_impl.dart:649:5)
E/flutter (25121): #10     _rootRunBinary (dart:async/zone.dart:1423:47)
E/flutter (25121): #11     _CustomZone.runBinary (dart:async/zone.dart:1315:19)
E/flutter (25121): #12     _FutureListener.handleError (dart:async/future_impl.dart:171:22)
E/flutter (25121): #13     Future._propagateToListeners.handleError (dart:async/future_impl.dart:852:47)
E/flutter (25121): #14     Future._propagateToListeners (dart:async/future_impl.dart:873:13)
E/flutter (25121): #15     Future._completeError (dart:async/future_impl.dart:649:5)
E/flutter (25121): #16     _rootRunBinary (dart:async/zone.dart:1423:47)
E/flutter (25121): #17     _CustomZone.runBinary (dart:async/zone.dart:1315:19)
E/flutter (25121): #18     _FutureListener.handleError (dart:async/future_impl.dart:171:22)
E/flutter (25121): #19     Future._propagateToListeners.handleError (dart:async/future_impl.dart:852:47)
E/flutter (25121): #20     Future._propagateToListeners (dart:async/future_impl.dart:873:13)
E/flutter (25121): #21     Future._completeError (dart:async/future_impl.dart:649:5)
E/flutter (25121): #22     _rootRunBinary (dart:async/zone.dart:1423:47)
E/flutter (25121): #23     _CustomZone.runBinary (dart:async/zone.dart:1315:19)
E/flutter (25121): #24     _FutureListener.handleError (dart:async/future_impl.dart:171:22)

Error inside of main

Connecting to VM Service at ws://127.0.0.1:59359/o9ni1p4hA3U=/ws
E/flutter (23171): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
E/flutter (23171): #0      FirebaseCoreHostApi.initializeCore (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:210:7)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): #1      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:29:44)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): #2      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:73:7)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): #3      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): #4      main (package:bt/main.dart:25:3)
E/flutter (23171): <asynchronous suspension>
E/flutter (23171): 
I/rple.btpinphon(23171): ProcessProfilingInfo new_methods=1237 is saved saved_to_disk=1 resolve_classes_delay=8000

I'm also getting this error on one Android device but not another.

No idea what's going on. I've ran flutterfire configure like I normally do with all projects. Everything is exactly the same as the others.

What's really strange is it works on my Samsung Tab A8 but not my Xiaomi Mi 9T.

Any suggestions would be greatly appreciated.

void main() {
  runZonedGuarded(() async {
    WidgetsFlutterBinding.ensureInitialized();

    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );

    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);

    FlutterError.onError = (details) {
      FirebaseCrashlytics.instance.recordFlutterFatalError(details);
    };

    PlatformDispatcher.instance.onError = (error, stack) {
      FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
      return true;
    };

    runApp(const MyApp());
  }, (error, stack) {
    FirebaseCrashlytics.instance.recordError(error, stack);
  });
}
environment:
  sdk: '>=3.1.0 <4.0.0'

  firebase_core: ^2.24.2
  firebase_crashlytics: ^3.4.9

What's really strange is that on the Samsung A8 Tablet I'm able to run the app but I've just noticed this error in the console:

W/Firebase-Installations(10727): Error when communicating with the Firebase Installations server API. HTTP response: [400 Bad Request: {
W/Firebase-Installations(10727):   "error": {
W/Firebase-Installations(10727):     "code": 400,
W/Firebase-Installations(10727):     "message": "API key not valid. Please pass a valid API key.",
W/Firebase-Installations(10727):     "status": "INVALID_ARGUMENT",
W/Firebase-Installations(10727):     "details": [
W/Firebase-Installations(10727):       {
W/Firebase-Installations(10727):         "@type": "type.googleapis.com/google.rpc.ErrorInfo",
W/Firebase-Installations(10727):         "reason": "API_KEY_INVALID",
W/Firebase-Installations(10727):         "domain": "googleapis.com",
W/Firebase-Installations(10727):         "metadata": {
W/Firebase-Installations(10727):           "service": "firebaseinstallations.googleapis.com"
W/Firebase-Installations(10727):         }
W/Firebase-Installations(10727):       }
W/Firebase-Installations(10727):     ]
W/Firebase-Installations(10727):   }
W/Firebase-Installations(10727): }
W/Firebase-Installations(10727): ]
W/Firebase-Installations(10727): Firebase options used while communicating with Firebase server APIs: AIzaSyCVgdp2oYid_v_le1ZCPT4O8ABmPrltzs4, bt-pin-phone, 1:124725696474:android:ab44c7c69b82c25fc612e3
E/Firebase-Installations(10727): Firebase Installations can not communicate with Firebase server APIs due to invalid configuration. Please update your Firebase initialization process and set valid Firebase options (API key, Project ID, Application ID) when initializing Firebase.

I've checked the firebase_options.dart file and can see there is definitely an API key present in the options. Maybe it's not getting sent with the rest of the info for some reason?

Solved this by running flutterfire configure again. Not sure why but for some reason firebase_options.dart was out of sync with google-services.json.

lindsaycharlotte2023 commented 5 months ago

我有一个项目,我曾经在 flutter版本 3.7.12 firebase_crashlytics: ^3.4.9 firebase_core: ^2.24.2 通过flutterfire configure --project 接入 ,iOS 能够正常使用,但是安卓 报以下报错 E/flutter (29382): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null) E/flutter (29382): #0 FirebaseCoreHostApi.initializeCore (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:210:7) E/flutter (29382): E/flutter (29382): #1 MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:29:44) E/flutter (29382): E/flutter (29382): #2 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:73:7) E/flutter (29382): E/flutter (29382): #3 Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31) E/flutter (29382): 如何解决,感谢

Lyokone commented 5 months ago

Seeing that multiple persons managed to get it working but updating the code to

await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

and run flutterfire configure again, I'll close this.

mahmodalali2003ali commented 5 months ago

Future main() async { WidgetsFlutterBinding.ensureInitialized(); Platform.isAndroid ? await Firebase.initializeApp( options: const FirebaseOptions( apiKey: "AIzaSyCPY3qgBEjs3Mgnlh_TuSrbrNBaCpw2mgs", appId: "1:572717615399:android:397ba11574ace4dce28102", messagingSenderId: "572717615399", projectId: "opject7", storageBucket: "opject7.appspot.com", )) : await Firebase.initializeApp();

runApp(const MyApp()); } You will find it in the google-services.json file options: const FirebaseOptions( apiKey: "AIzaSyCPY3qgBEjs3Mgnlh_TuSrbrNBaCpw2mgs", // "current_key": "AIzaSyCPY3qgBEjs3Mgnlh_TuSrbrNBaCpw2mgs" appId: "1:572717615399:android:397ba11574ace4dce28102", // "mobilesdk_app_id": "1:572717615399:android:397ba11574ace4dce28102", messagingSenderId: "572717615399", // "project_number": "572717615399", projectId: "opject7", /// "project_id": "opject7",

dakshrajput45 commented 4 months ago

@JobiJoba, did you follow those instructions? You are supposed to do

await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

DefaultFirebaseOptions.currentPlatform it is showing undefined