Search code examples
flutterflutter-dependencies

this is a bug when calling a channel method


Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.setMethodCallHandler(io.flutter.plugin.common.MethodChannel$MethodCallHandler)' on a null object reference
       at io.flutter.plugins.firebase.firestore.FlutterFirebaseFirestorePlugin.onDetachedFromEngine(FlutterFirebaseFirestorePlugin.java:1)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:23)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:28)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.removeAll(FlutterEngineConnectionRegistry.java:1)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.destroy(FlutterEngineConnectionRegistry.java:3)
       at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:4)
       at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach(FlutterActivityAndFragmentDelegate.java:15)
       at io.flutter.embedding.android.FlutterFragment.onDetach(FlutterFragment.java:4)
       at androidx.fragment.app.Fragment.performDetach(Fragment.java:3)
       at androidx.fragment.app.g0.i(FragmentStateManager.java:3)
       at androidx.fragment.app.g0.m(FragmentStateManager.java:46)
       at androidx.fragment.app.SpecialEffectsController$b.e(SpecialEffectsController.kt:2)
       at androidx.fragment.app.SpecialEffectsController$Operation.d(SpecialEffectsController.kt:4)
       at androidx.fragment.app.SpecialEffectsController.n(SpecialEffectsController.kt:21)
       at androidx.fragment.app.FragmentManager.U(FragmentManager.java:6)
       at androidx.fragment.app.FragmentManager.F(FragmentManager.java:5)
       at androidx.fragment.app.r.f(FragmentController.java:1)
       at androidx.fragment.app.o.onDestroy(FragmentActivity.java:2)
       at android.app.Activity.performDestroy(Activity.java:7241)
       at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1271)
       at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4484)
       at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4515)
       at android.app.ActivityThread.-wrap5()
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1690)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6626)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

this only happens in production, it doesn't happen to me in development and I don't know how to detect it because it doesn't tell me which library or sdk is calling that motodo channel... how can I find out which library or sdk is making that call ?


Solution

  • This seems to be a known issue - try to follow these instructions: https://github.com/firebase/flutterfire/issues/11740#issuecomment-1773842990

    TLDR: Open FlutterFirebaseFirestorePlugin.java file in your IDE and go to line 131. You'll see onDetachedFromEngine method, just comment out channel.setMethodCallHandler(null); line.