When I try to build my flutter project I noticed something weird. If I try to build it through the options in the images it goes through successfully, however if I try to build through the command line using "flutter pub get", "flutter build release", etc. it automatically tries to resolve dependencies and upgrade them.
Android Studio run options, which cause the project to build
Is there a way to stop the build from automatically try to upgrade the dependencies?
I have tried looking through the settings of Android Studio to see if there was an option selecter there that would set it, but I didn’t find anything useful.
2
Answers
It seems like you’re facing an issue with Flutter’s command line build process automatically trying to upgrade dependencies. This behavior can be influenced by the Flutter version management and package resolution settings.
Firstly, ensure that you have a consistent Flutter version specified in your pubspec.yaml file. This can be done by adding a flutter section like this:
Next, check if your pubspec.yaml file contains any version constraints for your dependencies. If not, consider adding specific version constraints to prevent unexpected upgrades. For example:
Now, if you still encounter the issue, make sure to run the following commands before building to ensure you have a stable environment:
The flutter clean command removes the build artifacts, and flutter pub get fetches the dependencies as specified in your pubspec.yaml. This helps in maintaining a consistent environment.
If the issue persists, you can use the –no-upgrade flag with the flutter pub get command to explicitly instruct Flutter not to upgrade dependencies:
This should prevent automatic upgrades during the build process.
Additionally, ensure that your Flutter SDK is up to date by running:
flutter upgrade
If none of the above solutions resolve the issue, consider checking the pubspec.yaml files of your dependencies to see if they have any constraints that might cause automatic upgrades.
I hope these suggestions help you resolve the issue. If you have any further questions or face any specific challenges, feel free to ask!
If you don’t want to upgrade your dependencies specified in pubspec.yaml file after you run ‘flutter build release’, write like below
some_dependency: 1.2.0 and not like some_dependency: ^1.2.0