Flutter - Problem with adding Firebase Messaging

8,087

Solution 1

Error.throwWithStackTrace was added in Dart 2.16 (Flutter version 2.10 from Feb 8, 2022).

You should either:

  • Update Flutter to 2.10: flutter upgrade
  • Or use older version of conflicting package: firebase_messaging_platform_interface: 3.1.6

Solution 2

Tried all of the proposals, here and in the link here: https://github.com/FirebaseExtended/flutterfire/issues/8181

But only that worked for me

dependency_overrides:
  firebase_messaging_platform_interface: 3.1.6
  firebase_crashlytics_platform_interface: 3.1.13
  cloud_firestore_platform_interface: 5.4.13
  firebase_auth_platform_interface: 6.1.11
  firebase_storage_platform_interface: 4.0.14
  cloud_functions_platform_interface: 5.0.21
  firebase_analytics_platform_interface: 3.0.5
  firebase_remote_config_platform_interface: 1.0.5
  firebase_dynamic_links_platform_interface: 0.2.0+5
  firebase_performance_platform_interface: 0.1.0+5
  firebase_app_installations_platform_interface: 0.1.0+6

This are the dependencies I am using in first place

  firebase_core: ^1.6.0
  firebase_crashlytics: ^2.2.1
  firebase_messaging: ^10.0.9
  firebase_analytics: ^9.1.0

Solution 3

I have faced the same problem and got a workaround for this.

Add firebase_messaging_platform_interface pubspeck.yaml:

dependency_overrides:
  firebase_messaging_platform_interface: 3.1.6

Solution 4

So I ran into this problem recently while using firebase_storage

What I did to solve the problem was... (I was on flutter 2.6 and dart 2.14).

Upgrade flutter and dart version: Into terminal, run flutter upgrade or in my case, flutter upgrade --force, since flutter upgrade was giving me some issues. Then I added the latest version of the dependencies to my pubspec (firebase_storage_10.2.0) At this stage, running the app will likely throw an error about unsupported compileSDKVersion or so, and ask you to upgrade. For that, go into your app level build.gradle file

("project"\android\app\build.gradle),

and under android, change the compileSDKVersion from it's current value to what flutter asks you to change to. in my case, it was from 30 to 31

android{
       //change compile sdk version to 31 (in my case. flutter will tell you which version you should set to)
       compileSdkVersion 31
}

When you run the app now, it will check for licenses for the Android SDK Package you just edited (31). it should automatically accept and install everything neccessary. Flutter run might then fail again, with the error of an incompatible kotlin version, and that you should update or so. To update the kotlin version, go to the project level build.gradle ("project"/android/build.gradle) change the kotlin version here (ext.kotlin_version = '1.3.5') to the latest version which can be found Here. as of now, the latest version is 1.6.10 so this line of code now reads

ext.kotlin_version = '1.6.10'

Now you are good to go. run the app again, it might take much longer than usual, but it should work just fine. Or at least it worked fine for me.

Solution 5

There were changes made to the dependencies of the Flutter Firebase packages https://github.com/FirebaseExtended/flutterfire/pull/8156

You can either update to use >=2.16 version of dart Or override the dependencies, you only need to add the ones that you are using

dependency_overrides:
  firebase_messaging_platform_interface: 3.1.6
  firebase_storage_platform_interface: 4.0.14
  cloud_functions_platform_interface: 5.0.21
  cloud_firestore_platform_interface: 5.4.13
  firebase_auth_platform_interface: 6.1.11
  firebase_database_platform_interface: 0.2.0+5
Share:
8,087
Carlos Castillo
Author by

Carlos Castillo

Updated on January 03, 2023

Comments

  • Carlos Castillo
    Carlos Castillo over 1 year

    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel stable, 2.5.0, on Microsoft Windows [Versión 10.0.19042.1348], locale en-US)
    [√] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc2)
    [√] Chrome - develop for the web
    [√] Android Studio (version 3.6)
    [√] VS Code (version 1.52.1)
    [√] Connected device (3 available)

    My pubsec.yaml has only:
    firebase_messaging: ^10.0.1
    firebase_core: ^1.2.1
    flutter_local_notifications: ^6.1.0

    The problem I am having even on a brand new Flutter Project is that I am getting the following error when I add import 'package:firebase_messaging/firebase_messaging.dart'; to main.dart

    /D:/Flutter/flutter_windows_2.5.0-stable/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:13:11: Error: Method not found: 'Error.throwWithStackTrace'.
        Error.throwWithStackTrace(exception, stackTrace);
              ^^^^^^^^^^^^^^^^^^^
    /D:/Flutter/flutter_windows_2.5.0-stable/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:16:9: Error: Method not found: 'Error.throwWithStackTrace'.
      Error.throwWithStackTrace(
            ^^^^^^^^^^^^^^^^^^^
    /D:/Flutter/flutter_windows_2.5.0-stable/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:11:7: Error: A non-null value must be returned since the return type 'Never' doesn't allow null.
    Never convertPlatformException(Object exception, StackTrace stackTrace) {
          ^
    
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Script 'D:\Flutter\flutter_windows_2.5.0-stable\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005
    
    * What went wrong:
    Execution failed for task ':app:compileFlutterBuildDebug'.
    > Process 'command 'D:\Flutter\flutter_windows_2.5.0-stable\flutter\bin\flutter.bat'' finished with non-zero exit value 1
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 15s
    Exception: Gradle task assembleDebug failed with exit code 1
    
    
  • Pavel
    Pavel about 2 years
  • Admin
    Admin about 2 years
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
  • Alejandro Rodríguez
    Alejandro Rodríguez about 2 years
    I updated the comment. I hope you find it useful.