Flutterfire: [cloud_firestore] App Unexpectedlyclosed, shutting down VM, Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference

Created on 8 May 2020  Â·  19Comments  Â·  Source: FirebaseExtended/flutterfire

Describe the bug
App closed unexpectedly while it was connected and idle. There was no user side interaction but there could be changes in the database which the app could be listening to.

To Reproduce
Could not reproduce this error, it seemed like a random event. Could not find out what triggered the crash.

Expected behavior
No such crash should have happened without triggering anything manually.

Additional context
Error logs

Shutting down VM
E/AndroidRuntime( 1822): FATAL EXCEPTION: main
E/AndroidRuntime( 1822): Process: com.piety.pietystore, PID: 1822
E/AndroidRuntime( 1822): java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
E/AndroidRuntime( 1822):        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$EventObserver.onEvent(CloudFirestorePlugin.java:451)
E/AndroidRuntime( 1822):        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$EventObserver.onEvent(CloudFirestorePlugin.java:433)
E/AndroidRuntime( 1822):        at com.google.firebase.firestore.Query.lambda$addSnapshotListenerInternal$2(com.google.firebase:firebase-firestore@@21.3.0:1025)
E/AndroidRuntime( 1822):        at com.google.firebase.firestore.Query$$Lambda$3.onEvent(Unknown Source:6)
E/AndroidRuntime( 1822):        at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0(com.google.firebase:firebase-firestore@@21.3.0:42)
E/AndroidRuntime( 1822):        at com.google.firebase.firestore.core.AsyncEventListener$$Lambda$1.run(Unknown Source:6)
E/AndroidRuntime( 1822):        at android.os.Handler.handleCallback(Handler.java:873)
E/AndroidRuntime( 1822):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1822):        at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime( 1822):        at android.app.ActivityThread.main(ActivityThread.java:6692)
E/AndroidRuntime( 1822):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 1822):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime( 1822):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/Process ( 1822): Sending signal. PID: 1822 SIG: 9
Lost connection to device.

Flutter doctor
Run flutter doctor and paste the output below:

[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Linux, locale en_IN)
    • Flutter version 1.12.13+hotfix.9 at /home/ashutosh/flutter
    • Framework revision f139b11009 (6 weeks ago), 2020-03-30 13:57:30 -0700
    • Engine revision af51afceb8
    • Dart version 2.7.2


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /home/ashutosh/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /home/ashutosh/Downloads/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Android Studio (version 3.5)
    • Android Studio at /home/ashutosh/Downloads/android-studio
    • Flutter plugin version 41.0.2
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build
      1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.44.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.10.1

[✓] Connected device (1 available)
    • ASUS X01BDA • JBAAGF08C383SR5 • android-arm64 • Android 9 (API 28)

• No issues found!
crowd cloud_firestore bug

Most helpful comment

Confirming the issue.

It seems to happen after resuming from background. Once the app is resumed and a value is written to Firestore, the app crashes.

After doing some research, the only related issue I could find was this issue on the cloud_firestore Github.

The issue suggested downgrading to 0.13.4+2 but that didn't seem to fix my issue.

Here's what we're using:

  firebase_storage: ^3.0.8
  firebase_core: 0.4.4
  cloud_firestore: ^0.13.4+2
  firebase_auth: 0.15.3
  provider: ^3.1.0

also see this issue for a detailed explanation: https://stackoverflow.com/questions/61615390/flutter-streamprovider-with-cloudfirestore-causing-error-on-resume?newreg=075deb3ba59d45ef9cc010addce872e6

All 19 comments

Hi @ashutoshsingh05
can you please provide your 'flutter run --verbose'?
Also, to better address the issue, would be helpful if you could post a minimal code sample to reproduce the problem
Thank you

Have you updated your project to androidx lately?

can you please provide your 'flutter run --verbose'?

Here's the output to flutter run --verbose

Also, to better address the issue, would be helpful if you could post a minimal code sample to reproduce the problem

I could not find the source of the problem or what triggered it. It seemed like a random event. I'm unable to reproduce the error. Will post an update if I found something.

Have you updated your project to androidx lately?

No, the project was created a month ago with the androidx flag enabled

is there any update !
I'm also facing this issue that make my app crashing , the Crashlytics catch that issue

Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$EventObserver.onEvent (CloudFirestorePlugin.java:451)
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$EventObserver.onEvent (CloudFirestorePlugin.java:433)
com.google.firebase.firestore.Query.lambda$addSnapshotListenerInternal$2 (com.google.firebase:firebase-firestore@@21.3.0:1025)
com.google.firebase.firestore.Query$$Lambda$3.onEvent (Unknown Source:6)
com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0 (com.google.firebase:firebase-firestore@@21.3.0:42)
com.google.firebase.firestore.core.AsyncEventListener$$Lambda$1.run (Unknown Source:6)
android.os.Handler.handleCallback (Handler.java:873)
android.os.Handler.dispatchMessage (Handler.java:99)
com.google.android.gms.internal.tasks.zzb.dispatchMessage (com.google.android.gms:play-services-tasks@@17.0.2:6)
android.os.Looper.loop (Looper.java:214)
android.app.ActivityThread.main (ActivityThread.java:7156)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:975)

Confirming the issue.

It seems to happen after resuming from background. Once the app is resumed and a value is written to Firestore, the app crashes.

After doing some research, the only related issue I could find was this issue on the cloud_firestore Github.

The issue suggested downgrading to 0.13.4+2 but that didn't seem to fix my issue.

Here's what we're using:

  firebase_storage: ^3.0.8
  firebase_core: 0.4.4
  cloud_firestore: ^0.13.4+2
  firebase_auth: 0.15.3
  provider: ^3.1.0

also see this issue for a detailed explanation: https://stackoverflow.com/questions/61615390/flutter-streamprovider-with-cloudfirestore-causing-error-on-resume?newreg=075deb3ba59d45ef9cc010addce872e6

Have the same issue and posted here https://github.com/FirebaseExtended/flutterfire/issues/2529
It seems to have to do with the cloud_firestore querysnapshot update handler and reconnecting. I can reproduce the error when I go to a screen that starts a stream, exit the app with the back button and then reopen the app and send data to the collection the stream uses

Same issue here! After logging in and out for 5 or 6 times the app throws the error.

I am experiencing the same issue. It happens a little while after doing some update to the firestore

Happened to me today. Also after changing something in Firestore like @Batzee said

Same issue here. I have a StreamBuilder listening to onAuthStateChanged, and when I start my app onto the login page, then press back, and then resume the app, and try to use my login button, I get a crash.

Also an important issue I missed about this error I am getting. I have tested this in 3 devices. And it only happens in Nexus 4 and Samsung Galaxy J7 which are running Android 6. This error does not happen in my Pixel 3a that is running Android 10. And I have set minSdkVersion as 21.

I'm getting the same crash. Reverting from 0.13.5 to 0.13.4+2 fixed the issue for me.

I'm getting the same crash. Reverting from 0.13.5 to 0.13.4+2 fixed the issue for me.

Downgrading to 0.13.4+2 seem to have fixed the issue for us. I've tried upgrading to 0.13.6 but the app would crash again after resuming from background.

I think there is an issue in the plugin code in line https://github.com/FirebaseExtended/flutterfire/blob/master/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java#L451

It should check if channel is null before accessing it. channelis set to null in onDetachedFromEngine.

This is also happening in physical device and in emulator as well. It happens in both debug and release modes. I don't have much to report, only the logs and doctor summary.

Physical device: Pixel 2 - Android 10
Emulator: Pixel 3a API 29

Logs:

D/AndroidRuntime( 9282): Shutting down VM
E/AndroidRuntime( 9282): FATAL EXCEPTION: main
E/AndroidRuntime( 9282): Process: app.myapp.android, PID: 9282
E/AndroidRuntime( 9282): java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
E/AndroidRuntime( 9282):    at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$EventObserver.onEvent(CloudFirestorePlugin.java:451)
E/AndroidRuntime( 9282):    at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$EventObserver.onEvent(CloudFirestorePlugin.java:433)
E/AndroidRuntime( 9282):    at com.google.firebase.firestore.Query.lambda$addSnapshotListenerInternal$2(com.google.firebase:firebase-firestore@@21.3.0:1025)
E/AndroidRuntime( 9282):    at com.google.firebase.firestore.Query$$Lambda$3.onEvent(Unknown Source:6)
E/AndroidRuntime( 9282):    at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0(com.google.firebase:firebase-firestore@@21.3.0:42)
E/AndroidRuntime( 9282):    at com.google.firebase.firestore.core.AsyncEventListener$$Lambda$1.run(Unknown Source:6)
E/AndroidRuntime( 9282):    at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime( 9282):    at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime( 9282):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime( 9282):    at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime( 9282):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9282):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime( 9282):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process ( 9282): Sending signal. PID: 9282 SIG: 9

Doctor summary

[✓] Flutter (Channel stable, v1.17.1, on Mac OS X 10.14.4 18E226, locale en-SA)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.45.1)
[✓] Connected device (1 available)

• No issues found!

Facing the same issue with Firebase Storage too.

D/AndroidRuntime( 9626): Shutting down VM
E/AndroidRuntime( 9626): FATAL EXCEPTION: main
E/AndroidRuntime( 9626): java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
E/AndroidRuntime( 9626):    at io.flutter.plugins.firebase.storage.FirebaseStoragePlugin.invokeStorageTaskEvent(FirebaseStoragePlugin.java:485)
E/AndroidRuntime( 9626):    at io.flutter.plugins.firebase.storage.FirebaseStoragePlugin.access$100(FirebaseStoragePlugin.java:39)
E/AndroidRuntime( 9626):    at io.flutter.plugins.firebase.storage.FirebaseStoragePlugin$15.onProgress(FirebaseStoragePlugin.java:441)
E/AndroidRuntime( 9626):    at io.flutter.plugins.firebase.storage.FirebaseStoragePlugin$15.onProgress(FirebaseStoragePlugin.java:438)
E/AndroidRuntime( 9626):    at com.google.firebase.storage.StorageTask$$Lambda$5.raise(Unknown Source:4)
E/AndroidRuntime( 9626):    at com.google.firebase.storage.TaskListenerImpl.lambda$onInternalStateChanged$2(com.google.firebase:firebase-storage@@17.0.0:94)
E/AndroidRuntime( 9626):    at com.google.firebase.storage.TaskListenerImpl$$Lambda$3.run(Unknown Source:6)
E/AndroidRuntime( 9626):    at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime( 9626):    at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime( 9626):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime( 9626):    at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime( 9626):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9626):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime( 9626):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

I, also encountering this issue as of this time. I am using the latest firestore_auth 0.16.1 and cloud_firestore 0.13.7.
Whenever I tried to log in to the app > go ho home screen > press the back button (Android) > open the app > log out., the app suddenly crashes. Both on test and release build. I tried also in both real devices (Android 9) and Emulator (Android 5). Same triggering the issue.

Was this page helpful?
0 / 5 - 0 ratings