Reputation: 171
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
Upvotes: 12
Views: 20503
Reputation: 1
Do this simply
One Line Answer: Upgrade all the packages using your terminal
Step 1: List out all the outdated packages: "flutter pub outdated" (in terminal)
Step 2: Upgrade the packages: "flutter pub upgrade --major-versions" (in terminal)
It helped me, I hope it will apply the same to you
Upvotes: 0
Reputation: 2484
This throwWithStackTrace method was added in flutter's dart-core since 2.16 flutter version. The workaround would be adding the dependency_overrides just like how we add
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
and
dev_dependencies:
flutter_test:
sdk: flutter
now we have to add dependency overrides in the same manner as dependencies and dev_dependencies. Example:
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
Reference: Issue created in flutter's github
Upvotes: 0
Reputation: 1
I was obtaining the following error:
{flutter-folder}/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_web-2.2.9/lib/src/internals.dart:11:20: Error: Method not found: 'guardWebExceptions'. return internals.guardWebExceptions( ^^^^^^^^^^^^^^^^^^
I recently solved it adding firebase_messaging_web: 2.2.7 to my dependency_overrides section
dependency_overrides:
firebase_messaging_web: 2.2.7
You can see the package available versions at https://pub.dev/packages/firebase_messaging_web/versions
flutter --version
https://github.com/flutter/flutter.git<
Framework • revision 097d3313d8 (10 days ago) • 2022-02-18 19:33:08 -0600
Engine • revision a83ed0e5e3
Tools • Dart 2.16.1 • DevTools 2.9.2
pubspec.yml
dependencies:
firebase_messaging: 10.0.9
I hope you find this usefull. I was facing this problem for a long time.
Upvotes: 0
Reputation: 146
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.
Upvotes: 2
Reputation: 703
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
Upvotes: 3
Reputation: 241
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
Upvotes: 11
Reputation: 1285
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
Upvotes: 5
Reputation: 5876
Error.throwWithStackTrace was added in Dart 2.16 (Flutter version 2.10 from Feb 8, 2022).
You should either:
flutter upgrade
firebase_messaging_platform_interface: 3.1.6
Upvotes: 14
Reputation: 72
As suggested in this post(how to solve Execution failed for task ':app:compileFlutterBuildDebug') you should try to run in your terminal "Packages get | Pub get" and then build the project again
Upvotes: -2