google_maps_flutter and AndroidX migration - flutter

I am working on a project that requires google_maps_flutter package. When selecting the option Run -> Flutter run in Release Mode I receive:
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See for more information on the problem and how to fix it.
If I follow the documentation to Avoiding AndroidX from the official page:
https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility#avoiding-androidx
I have the following issue:
The last available version pre AndroidX for google_maps_flutter is 0.1.0
Seems that this version does not exist.
Log Error:
Because depends on google_maps_flutter 0.1.0 which doesn't match any versions, version solving failed.
pub get failed (1)
Is there a solution for this problem?

You are facing the issue because the package version is too old.
Latest version for google_maps_flutter is 0.5.13
Follow instructions which are mentioned in the Google maps flutter package here
Follow instructions from here to migrate your flutter app to AndroidX.

Related

Why is riverpod failing even to initialize in project? Method not found: 'Error.throwWithStackTrace'

So i am trying to get started with riverpod and creating a new flutter project with the "click and counter" default sample.
As soon as I add on the pubspec
flutter_hooks: ^0.18.0
hooks_riverpod: ^2.0.0
And
import 'package:hooks_riverpod/hooks_riverpod.dart';
I get this error on the debug console and can't figure it out what is the problem
: Error: Method not found: 'Error.throwWithStackTrace'.
../…/framework/provider_base.dart:904
Error.throwWithStackTrace(error, chain);
^^^^^^^^^^^^^^^^^^^
: Error: A non-null value must be returned since the return type 'Never' doesn't allow null.
../…/framework/provider_base.dart:898
Never _rethrowProviderError(Object error, StackTrace stackTrace) {
^
Error.throwWithStackTrace was added in Dart 2.16 (Flutter version 2.10 from Feb 8, 2022).
https://api.flutter.dev/flutter/dart-core/Error/throwWithStackTrace.html
(Check the #Since annotation.)
If your Flutter/Dart version is below that, you'll get the error you saw.
Two options that may help are:
Specify an exact version of dependencies (don't use ^ ahead of version)
upgrade Flutter/Dart to at least 2.10/2.16
flutter upgrade
If your problematic package (hooks_riverpod: ^2.0.0 in your case) is listed with ^, it'll use the latest version that doesn't break dependencies.
I'm guessing that when you created a new project and used that same dependency version, upon initial pub get it downloaded a newer version of the package (or a newer version of a dependency that that package uses) into "pub cache" which is relying on the new Error API method.
Your project will store this information in:
<your_project_dir>/dart_tool/package_config.json
The min Dart SDK version listed for the package should normally have changed from 2.12 to 2.16. (update: it's been updated now) This would give us a hint that we need to update our Flutter/Dart if we see our build failing.
In an earlier version of this answer, I noted that the ^ prefix on package dependency versions is supposed to prevent these types of issues, but I'm no longer certain it was meant to cover this situation where the underlying platform needs to be updated (as opposed to a breaking change in the API of the package itself).
Anyways, at first glance, it might make sense to go from 2.0.0 to 3.0.0 for a package version # when it depends on a new core Dart API method that did not exist when 2.0.0 was published.
Notes
The author of riverpod also wrote the new API for Error.throwWithStackTrace so likely the latest version of hooks_riverpod is using the latest API changes. (The version you're listing 2.0.0 is pre-release currently). You could try earlier versions of riverpod in your pubspec.yaml (such as 1.0.3)
for anyone facing " Method not found: 'Error.throwWithStackTrace' " with firebase.
try to add this to your pubspec.yaml
dependency_overrides:
firebase_messaging_platform_interface: 3.1.6
I saw this.
How about trying flutter pub upgrade?
If it is not resolved, then check analyzer version and check which dependency locks that.
As noted in Baker's answer, Error.throwWithStackTrace was recently added in Dart 2.16.
If you're getting an error about Error.throwWithStackTrace not being found for some package, the package author neglected to update their package's minimum Dart SDK version. You should report that to the package maintainer. In the meantime, you should use an earlier version of the problematic package or use a newer version of the Dart SDK.
Try running flutter upgrade
By this it will upgrade your flutter and dart SDK version and hope it resolves your issue
if you are still facing the issues after "flutter upgrade" or you use this line of code in pubspec.yaml
dependency_overrides:
firebase_messaging_platform_interface: 3.1.6
you receive this type of errors
java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)
at com.sun.tools.javac.util.Assert.error(Assert.java:133)
at com.sun.tools.javac.code.TypeAnnotations.annotationType(TypeAnnotations.java:231)
at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.separateAnnotationsKinds(TypeAnnotations.java:294)
at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitMethodDef(TypeAnnotations.java:1066)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:275)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
so Try to upgrade your gradle version, this line in your build.gradle
classpath 'com.android.tools.build:gradle:4.1.0'
after doing that it may be possible it ask you to change your
gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip
to
distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip
also upgarde this packages
firebase_core: ^1.10.0
firebase_messaging: ^11.1.0

The plugins `advance_pdf_viewer, flutter_webview_plugin` use a deprecated version of the Android embedding

The plugins advance_pdf_viewer, flutter_webview_plugin use a deprecated version of the Android embedding.
To avoid unexpected runtime failures or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of
Flutter will remove these deprecated APIs."
I follow some documentation but is still not working.
i upgrade and downgrade my version but still not working.
should I share my mainActivity.kt and manifest file?
if there is no newer version of advance_pdf_viewer, flutter_webview_plugin available with the new android V2 embedding, your can't do anything inside of your app. Keep watching for plugin updates of these 2 plugins... or go to it's github project and open an issue to fix it. Sometime the master branch has already fix it. In this case you could try to link direct to the master branch and not to a version in pub.dev
for advance_pdf_viewer i use $flutter pub add advance_pdf_viewer
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
dependencies:
advance_pdf_viewer: ^2.0.1
Alternatively, your editor might support or flutter pub get. Check the docs for your editor to learn more.
Import it
Now in your Dart code, you can use:
import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
and for webview I try dependencies:
flutter_webview_plugin:
git: https://github.com/nuc134r/flutter_webview_plugin.git
and it all works for me than you.

Error in Flutter while using Provider tool

I am building a basic app using flutter, in which I had to use provider, I added Provider dependencies in pubspec.yaml file but getting this error please help, I added the error below not able to fix this problem I have the latest flutter SDK
To solve this use lower version of Provider dependency as newer version of provider depends on newer version of Flutter SDK and your application's Flutter SDK is old one so it will have compatibility issues, So just degrade the version of dependency or you can also run pub outdated command and it will suggest you compatible version as per your SDK.

The plugin admob_flutter uses a deprecated version of the Android embedding

when i put admob_flutter: ^2.0.0-nullsafety.1 in pubspec, and type on cmd flutter pub get this error occurs!
The plugin admob_flutter uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of
Flutter will remove these deprecated APIs.
It's for latest flutter updates. so you can't do anything. Please use other package or wait till fix the problem by package developer because this error is produced after flutter version 2.5.
I have downgraded my flutter version by command flutter downgrade and it shows an option of a downgraded flutter version and it resolves my error.
Downgrading flutter worked for me.

Dart 2.6 and Flutter, Upgrading Dependency

Using Flutter, I am trying to update my dart dependency 2.6.0 but I get an error
Because *project_name* requires SDK version >=2.6.0 <3.0.0, version solving failed.
pub get failed (1)
exit code 1
I want to use the new features that dart offers, such as Extension Methods. How could I go about upgrading my dependency? I have installed the newest stable version of dart on my computer, but regardless I still get that error.
A couple of things that might help:
From this issue, you can try ensuring that you've updated enviroment in your pubspec.yaml file like so:
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Another thing that might help is just double checking the steps in this post or on the dart installation page to ensure that you've updated to the latest version correctly.