Flutter dependencies not working - android

I am trying to get the tutorial project startup_namer running. I am getting following error after I added english_words dependency on pubspec.yaml
Resolving dependencies...
The Flutter SDK is not available.
Flutter users should run `flutter packages get` instead of `pub get`.
Any idea on how to resolve this? I followed Google getting started documentation but didn't work out for me :(

Run this command in terminal/Command Prompt
flutter doctor
It automatically installs the missing dependencies or download the flutter sdk if necessary
if already install still problem exists run
flutter upgrade

You can check this link to get the Flutter SDK installed on your machine. If you already have the SDK and want to install the dependencies in pubspec.yaml, run this command in the project's root folder:
flutter packages get

If you get this error message in Android Studio then you probably don't have the Flutter plugin installed.
I just could reproduce that and for example opening the pubspec.yaml asked me to install the plugin and then the error was fixed.
You can also install it manually using the preferences.

Related

Flutter run from terminal works while manually not

When I run flutter build apk --release everything works just fine, In addition when I connect my phone to the computer and run flutter install -v everything is ok. Also when I run flutter run -v my app is working on my phone just fine.
BUT when I'm sending the apk manually to my phone, install and open my app, it's stuck on the splash screen.
I don't know what can case it not to work manually (since I cannot track my logs).
I'm using firebase, my google-services.json is up to date.
flutter doctor is just fine.
android SDK version 30.0.2.
app/build.gradle compileSdkVersion 30.
gradle version 6.6.1.
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.android.tools.build:gradle:4.0.2'
Any suggestions how to validate my application? What can case such a problem?
Thanks you!!!
More Information
The only error on flutter run is:
Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.name.name signatures do not match previously installed version; ignoring!]
but as I said before the flutter run do works and my app uploads correctly, so I think it is not related to my problem.
Have You implemented release SHA keys ?
After many tests using flutter run -v I encountered that in some cases I'm getting:
Unhandled exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
I do work with shared_preferences package and that answer sure solve my problem https://stackoverflow.com/a/63027655/12695188
Although this is a specific solution I will describe what I have done in order to find my problem:
flutter pub get
flutter build apk --debug
flutter build apk --profile
flutter build apk --release
connect your physical device to your computer
flutter install -v (to your physical device)
flutter run -v
Solve each problem you find on flutter run -v.
Hope this will help someone out there.

Ionic 4 Running on Device: "Could not find an installed version of Gradle either on Android Studio or in System" Although I have it on my system

I'm trying to run a blank app of ionic 4 on my android 9 device. Already followed each step on the website and running it on browser is okay.
When I run it on my device here is what i get:
Error when running
It says I dont have gradle and android studio but here is my environment:
android sdk list,my /etc/environment,and my npm, ionic, gradle and java versions
Am I missing something guys?
This error occurs when gradle is not properly installed. I have experienced this before. try installing gradle on your system.
For some reason the ionic project does not locate the gradle, to verify that this is the case, try opening the project on android studio and you will get the warning that no gradle wrapper was found.
IDK if some of you people have the same problem, but it's because of the Gradle. Installed it the way the website said, tried both automatically with SDK manager and also the manual downloads. Still no. So I installed it using:
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle
Then find location where it was installed then add to path. Now I can install the app on my device
Your question is not clear, are you facing error on local emulator or real mobile device?
it seems you are trying to run on local android emulator, can you please mention that where you are facing error?
Also, please do debug or production build with the help of ionic cordova build android command and try to run on your android device, generally android studio will pops up of gradle build update, which will help to generate faster sequential android build, and which needs gradle for it.

Missing "curl" tool. Unable to download Dart SDK. Consider running "sudo apt-get install curl"

I facing this issue in flutter after adding dependency shared_preferences: ^0.5.3+4 in pubspec.yaml file.
After added the dependency, it suggest me to update flutter sdk for use the version of the dependency. So I just run flutter upgrade. After that I'm not able to run the application and for every command (Flutter upgrade, Flutter doctor etc), throws the below error.
Missing "curl" tool. Unable to download Dart SDK. Consider running
"sudo apt-get install curl".
Process finished with exit code 1
I also run command sudo apt-get install curl and get below result.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
curl : Depends: libcurl3-gnutls (= 7.47.0-1ubuntu2) but 7.47.0-1ubuntu2.12 is to be installed
E: Unable to correct problems, you have held broken packages.
Please guide me to get out of the problem.
Just open your terminal (if Ubuntu). Then type
sudo apt-get install curl
Then try to upgrade the Flutter Sdk. it will work.
NB: Before upgrading, you must take a backup of your present code. Or some API may show as deprecated and that will affect your project.
just go the place you install flutter and delete the flutter that you downloaded and download a new one the error will go

Flutter: pub get failed (66)

When i try to implement scoped model, i get this error message:
[flutter_course] flutter packages get
Running "flutter packages get" in flutter_course...
Creation of temporary directory failed, path = 'C:\Program Files\flutter.pub-cache_temp\dir' (OS Error: Access is denied.
, errno = 5)
name: flutter_course
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
scoped_model: ^1.0.1
dev_dependencies:
flutter_test:
sdk: flutter
What worked for me is: flutter pub cache repair
reference
I FINALLY GOT THE SOLUTION
Hello guys I finally found a solution to this error.
So the problem is first caused because temporary files could not be created in the /bin or .pub-Cache
To fix this go to their respective folders which are in the flutter folder and the first start with the bin folder and change its security options to allow for ALL APPLICATION PACKAGES and then the .pub-Cache the same .
Run flutter doctor and if you get a license error just follow the steps given by flutter doctor and you are good to go.
Try to clean Flutter: flutter clean and then update pub with: flutter packages upgrade or update Flutter with: flutter upgrade.
This happens to be an active issue and the flutter team is currently working on it. The problem is specific to the Windows operating system. You can try the following workarounds for now:
1) Make sure your installation does not reside in any directory which requires special privileges like Program Files. If that's the case, you can try running it as admin for now but you should change your installation directory to a user's data directory as soon as possible (#Günter Zöchbauer has already pointed this out in the comments).
2) Try restarting your machine.
3) Try deleting the .dart_tools folder and also try clearing the cache in flutter/bin/cache
4) Try disabling your antivirus and/or windows defender temporarily (although it's not really possible for people working on corporate machines). This issue could have been caused by an active antivirus locking your files temporarily.
Enable in your windows settings the Developer Mode.
An easy solution that worked for me on Windows was to run Android Studio as administrator.
After that, the error no longer appeared.
If you have tried all answers here.
You should try this, it worked for me.
(in android studio) Delete the pubspec.lock file in your project.
(in android studio) Execute this-- Tools > Flutter > Flutter clean
Go to flutter sdk folder where you have downloaded it. In my case C:\src\flutter\
Run this below command.
C:\src\flutter\bin\cache\dart-sdk\bin>flutter pub cache repair
After completion run pub get again in your android studio. It should work.
Turning on developer mode solved my issue on Windows 10.
Delete temp folder in pub cache.
Do pub repair flutter pub cache repair.
Turn on developer mode in windows settings.
Flutter clean and delete pub.lock if exist.
Try flutter pub get.
This worked for me.
Because I switched the Flutter version, the following operation worked for me
flutter clean
flutter pub get
Update the Flutter sdk using : flutter upgrade.
And also scoped_model in this link scoped model is showing dart 2 incompatible
You get this error because "packages get" command attemp to delete file in ...flutter.pub-cache_temp. Delete files manually in this loction, this is may not perfect solutions but it's works.
Sometimes newly installed packages could cause this. Uninstall and install package again
I downloaded flutter sdk and extracted file in C:\FlutterDev\ and then start android studio
remember to provide flutter sdk path if you changed
I had a similar situation when I upgraded the flutter version to the new 2.2.
As a solution, I ran the command line as administrator (or terminal for linux users) in the Project folder and run the following commands:
flutter pub cache repair
2.flutter pub get
I have tried all the solutions mentioned above none worked for me.
Then I went to file(any .dart) which has dependency error then click on get dependency. it works for me.
I have tried
Flutter clean X
Flutter pub cache repair X
Add Security X
Delete Temp X
last ....
I just open the windows setting developer mode O
My solution was to run
flutter pub get
it in an external terminal not from android studio
Also I set windows as developer, I ran in terminal and turned developer mode on
start ms-settings:developers
not sure which one helped.
try this, it solved my error,
terminal->flutter clean, then flutter pub get after this you will get the reason for error ,
in my case i was using latest version of path dependencies(path ^1.8.3) but sdk depended on path ^1.8.2,
so i changed path dependency from path ^1.8.3 to path ^1.8.2, in pubspec.yaml and error solved...
In my case it was anti-virus, I turned it off for a few minutes it started working.

Visual Studio Code - Target of URI doesn't exist 'package:flutter/material.dart'

I've just set up my Macbook for flutter development,
So I downloaded flutter SDK, and placed it in my Documents. After, I set up my path variable to work with flutter in my command line.
I execute the command flutter create todolist so I achieve a blank project.
I also set up my visual studio code with Dart-Code so I have the proper syntax highlight, IntelliSense, etc.
So when I open visual studio code, it highlights the import method, like the following image:
This means that it also highlights the classes that are correct, making it completely hard to understand if it's a real error or not.
I have executed both pub get and flutter packages get and got everything correctly.
I have my path variables all correctly.
Why is it highlighting it cannot find that 'import' package?
flutter packages get
Restart Visual Studio Code
source: https://flutter.dev/docs/development/packages-and-plugins/using-packages
flutter clean
flutter packages get
flutter packages upgrade ( Optional - use if you want to upgrade packages )
Restart Android Studio or Visual Studio
Author of the Dart Code plugin here! From the screenshot, I would say this is because your flutter project is in a sub-folder of the folder open in Code. We only scan the opened-folder to check whether it's a Flutter project - which then changes the SDK we launch and also enables the Flutter functionality (like the daemon and debugger).
You should re-open the "todo" folder directly.
If you want to have multiple projects open together, use multi-root workspaces, since Dart Code is multi-root-aware and will check each of the folders in the workspace when deciding if it needs to enable Flutter functionality.
Update
This case should be better supported in the Dart plugin now, so opening the immediate parent folder of a Flutter project should work as expected.
If you have used the flutter packages get command and the error still persists, you can simply reload VS code the Developer: Reload Window command. Simply type that in after pressing Ctrl+Shift+P (Cmd+Shift+P for Mac users). It will clear the error. It's like refreshing VS Code.
Restarting visual studio code worked for me !
Restart the VS Code you will see magic!
If that's not work then check the indent of your dependencies in the pubspec.yaml
Open the project after deleting .idea folder and .dart_tool
This worked for me in Android Studio as well as VS Code. I only had to run these lines in my terminal/command prompt and problem was solved. There was no need to restart any of the IDEs again
flutter packages get
Optionally you also run.
flutter upgrade
-Edit:- Now this happens most of the time to me, whenever I open some old project(flutter project), it is basically because of not downloading or not having the packages to refer, for the vscode, In simple just blindly do A PUB GET or just hit CTRL/COMMAND + s in pubspec.yaml file, and you are good to go(sometimes it might take some time to get everything set(depends on your system specs.))!
-old answer starts here!
Simple thing I did after Someone said here to restart the VSCode and I did that, and now everything works fine.
For me it was because just when I was creating project I got an notification for updating my dart(or related) extension and for that I did it and boom as my project started, it just gave me around 30 errors which do scared but the simple FIX was to RESTART THE EDITOR.
Open the command palette (ctrl+shift+p), type flutter: get packages (should autocomplete); after it resolves open the command palette again and type reload window and execute the command. This should resolve the issue as quickly as possible.
Close the VS Code and Run it again
The quickest way to get Dart-Code to reliably find your Flutter install and use it is to create a new FLUTTER_ROOT environment variable and set it to your Flutter path.
Basically
Check for correct indentation of your package in dependencies
if your editor supports, it automatically runs -> flutter pub get
Either way -> open terminal-> flutter pub get or flutter packages get
check .packages file, see if your package is present else reinstall package
Most important : Restart your IDE (Visual studio or Android Studio)
Start debugging your project
Most probably , your errors will be fixed by then
Hope it works for you
try to run flutter clean
then restart VS Code. This did it for me.
I also had this issue. I had both VS code and Android studio installed in my system.
The error was in VS code.
When i opened the same project on Android studio, the dependency was not actually added to pubsec.yaml. I added it there and ran pub.get.
When I returned to VS Code and everything was working fine.
So, Try opening it in other editor if you have, or through NotePad.
Edit:
Opening widget_test.dart and running it should also solve your issue.
Also happened to me while trying to run the project inside of another directory.
Worked by using the root directory of the main project
Just add
dependencies:
http: ^0.12.0
in pubspec.yaml file
please check http documentation
If you execute From the terminal: "Run flutter packages get" and the error continues, check is all packages directories are listed at '.packages' file. - Sometime you have the packages, but it is not configured at this file.
Execute one of the following:
flutter upgrade
flutter pub get
flutter packages get
Warning! This package referenced a Flutter repository via the
.packages file that is no longer available. The repository from which
the 'flutter' tool is currently executing will be used instead.
running Flutter tool: /opt/flutter previous reference :
/Users/Shared/Library/flutter This can happen if you deleted or moved
your copy of the Flutter repository, or if it was on a volume that is
no longer mounted or has been mounted at a different location. Please
check your system path to verify that you are running the expected
version (run 'flutter --version' to see which flutter is on your
path).
Checking the output of the flutter packages get reveals that the reason in my case was due to moving the flutter sdk.
Do not forget:
export PATH="$PATH:/home/[xxxxx]/flutter/bin
For me, it works:
flutter upgrade
flutter packages get
You can check with
flutter doctor
flutter --version
Go to pubsec.yaml file and add this directly after cupertino_icons:
webview_flutter:
Then press Packages get on the top right corner and it will work fine with you.
Add dependencies.
for example:- import 'package:audioplayers/audio_cache.dart';
in the above package if we only use this package then it shows error
but if we add dependencies in pubspec.yaml
such as
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
audioplayers: ^0.14.1
then click on packages get.
as you see this, I can also insert dependencies so if you insert dependencies along with your package then you are good to go.
If you change the property name in pubspect.yaml all your package in lib folder turn to red with the error Target of URI doesn't exist...
I was using (goggle location picker (with much more customisation in functions and UI) ) so I copy this package(complete) and using in my app in one folder but since dart code analyser analyses one flutter project so I found that those which are referencing from inside of this package is not working then I copy only lib folder(of google location picker) in my original project folder and voila this worked for me.
This solution took me a time of 3 days.
I know this is not the question but it might help someone to save 3 days.
I had this problem in Android Studio with the rflutter_alert package. After inserting the dependencies, I imported the package in my project with ctrl+space key and I have added import 'package:rflutter_alert/'; the problem is that this was not correct. The correct form was package:rflutter_alert/rflutter_alert.dart
right vs wrong comparison
i faced the same issue with the bloc package, after i restarted visual studio i installed the package again using flutter pub add bloc and it installed properly this time. Note that i tried installing it several times, this time it was a charm
Restart you android studio or visual studio.
Run commands
i - flutter clean.
ii - flutter pub get.
iii - flutter upgrade.
if these work not work try this:
Check your dart SDK path.
Don't forget to save pubspec.yaml before running "flutter pub get". Restarting Visual Studio Code is not enough. That was my solution. Sometimes when you work with intellij you forget that ...
When you usually get this error message:
Target of URI doesn't exist: 'package:foo'. Try creating the file
referenced by the URI, or Try using a URI for a file that does exist.
Example:
Target of URI doesn't exist:
'package:random_string/random_string.dart'. Try creating the file
referenced by the URI, or Try using a URI for a file that does exist.
import 'package:random_string/random_string.dart';
It is because a dependency is missing.
So all you have to do is find out what packages are needed by googling your package name.
Install the dependency:
$ flutter pub get
and add the dependency in the pubspec.yaml file:

Categories

Resources