Android studio has several problems regarding Flutter - flutter

I am new in android studio and flutter and I have encountered several problems after installing them. I already went to flutter doctor and it's all checked so flutter isn't the problem. I can't start coding because of these problems:
Here the sample code made by flutter itself I can't run it has several errors and
Here I can't run any virtual device because it says that I don't have an internet connection which is not true. I cannot code if I can't run the sample dummy code.
Thanks

I think you haven't properly done the setup for Android Studio. Please check the documentation where you will get steps for proper installation.
Few things which you can check:
Flutter and Dart plugins should be installed in Android Studio
If you want to run on an emulator, you will have to download the image for it whose answer you can find in previous answers.
When you first open Android Studio, you should get an option to create a Flutter Application.

Try to reinstall android studio with stable internet connection.

i would advise you to follow below steps to download system images to create virtual device
Select sdk manager
Download a system image by selecting show package details.You can download api32 system images which is the latest for now.
Once downloaded you can see the image file while created avd.

Some errors i got and how i fixed it
(ERROR 1) [flutter] flutter doctor -v 'crumb' is not recognized as an internal or external command, operable program or batch file. Error: Unable to find git in your PATH. exit code 1
(FIX) Go to flutter installation folder and inside flutter/bin edit the flutter.bat file using a text editor and remove the line (20) that says
IF EXIST "%mingit_path%" SET PATH=%PATH%;%mingit_path%
The code should look like this on those lines
REM If available, add location of bundled mingit to PATH
SET mingit_path=%FLUTTER_ROOT%\bin\mingit\cmd
Save and Run flutter doctor and everything should work fine.
(ERROR 2) flutter doctor takes too long
(fix) I downloaded the previous version of the sdk it worked like a charm
(ERROR 3) Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to resolve this.
(fix) Open Android Studio
Tools Menu, SDK Manager
In the window that comes up there are inner panels, choose SDK Tools panel
Tick Android SDK Command-line Tools
Choose Apply button near the bottom of the window
This worked
(ERROR 4) `The term 'flutter' is not recognized as the name of a cmdlet, function, script file, or operable program.
(fix) put the correct part in the env variables like i had put D:\flutter insted of D:\flutter\bin that worked

Related

Cannot Create Flutter Project in Android Studio due to missing pubspec.yaml

Whenever I create the Create new Flutter Project in android studio,
It's always throwing out this error: Please help.
Could not find a file named "pubspec.yaml" in "/Users/<usrname>/AndroidStudioProjects/inventory_system". pub get failed (66; Could not find a file named "pubspec.yaml" in "/Users/<usrname>/AndroidStudioProjects/inventory_system".)
First of all make sure your flutter is properly installed on your system. Faced the same issue. Try checking your installation and make sure everything is installed properly. Use this link: https://flutter.dev/docs/get-started/install
Just uninstall android as well as flutter. Try installing them again. First download and install Flutter. Then download and install Android Studio. Follow the proper installation process. I guess your issue is because of the unproper installation.
After flutter installation, open the folder where you have installed it, and open the file flutter_console which is a batch . It will open a console and then type:
flutter doctor
This will show you whether all the installation is properly carried out or not. But a better way is to perform proper installation.
Also you need to set environment variable after the installation.
Here is what happened with me when I installed flutter and android. This is just to show you the issue I had faced after installation
I then followed what was been said as error and got my flutter and android studio working.
Open the terminal.
Create the folder for your project by typing the command:
mkdir my_awesome_project
Navigate to the created folder:
cd my_awesome_project
In the folder type the command for project creation:
flutter create myawesomeproject
Open the AndroidStudio and then open the created folder.
Now you are ready to run and develop your app.
the easiest and simplest way to create new flutter project is to add flutter plugin to android studio/vs code and selecting SDK dir and then you can simply create new flutter project by clicking on buttons
and you can check flutter official guide

Can not install Flutter on MacOs, Tells that the unzip process is not working

When I try to install
unzip ~/Downloads/flutter_macos_2.2.2-stable.zip
this message pops up
unzip: cannot find or open /Users/user/Downloads/flutter_macos_2.2.2-stable.zip, /Users/user/Downloads/flutter_macos_2.2.2-stable.zip.zip or /Users/user/Downloads/flutter_macos_2.2.2-stable.zip.ZIP.
I don't what to do to install Flutter to OSX (vscode)
I can obtain flutter for Android Studio with no problems.
Also can't access flutter by itself on iTerm or Terminal.
First, it seems that your archive has two extensions .zip.zip, but it's probably not the problem you're facing.
You may want to check if your iTerm has the necessary permissions to access the content of the folder "Download" since it's a special folder for MacOS.
Second, for creating a flutter project through VSCode, you need to run the command flutter create myprojectnamehere, you will not have a button to create a flutter project like on Android Studio.
If you still facing issues with the installation of Flutter, you may want to checkout Flutter_Installer which is a Flutter GUI Installer made with Flutter.

flutter error Could not find an option named "platforms"

I'm new to learning flutter when I try to crate a new project on android studio gives me a arror message in the event section enter image description here
The MESSAGE: [Could not find an option named "platforms". Run 'flutter -h' (or 'flutter -h') for available flutter commands and options.]
And another problem is flutter doctor does not see the android studio enter image description here
1(By the way, I want to use this version of flutter, please do not give a suggestion like update.)
2(this problem did not exist before, it happened after turning my computer off and on)
And sorry for my english mistakes
Thank you.
flutter version flutter_windows_v1.12.13+hotfix.9-stable
andorid studio version: 4.1.3
Is this the answer to your question about andorid studio?
and you need to install JDK
You are using the wrong flutter SDK. Too low information in your question. Make sure that you have the right path to flutter SDK in your IDE. Check that the flutter SDK directory has the appropriate structure, all needed files and cetera. Channel and version of flutter also may have an influence on this problem.
Got this today out of nowhere. Things were going well, but suddenly when I tried to relaunch the app from fresh, for the error Could not find an option named "target"
UPDATE:
This appears to happen when I switch branches and merge while app is running/flutter is attached. If you're using VS Code,
open your launch.json
change something, I decided to change type: "dart" to type: "notdart"
save
try to debug which fails
then revert that change.
This should fix the issue.
Previous Answer/If you're not using VS Code
What worked for me was to
flutter clean
close the editor (VS Code for me)
close the emulator
give a minute for things to close down
open task manager and kill any left over processes of dart.exe flutter.exe and java.exe and adb.exe (was doing Android)
start VS Code/Android Studio and try to debug again. (when prompted I chose to cold boot the emulator as well)
This takes a while as the emulator has to cold boot and since flutter clean was run, the compilation hadto start from scratch as well.

VSCode Can't Find the PATH To the Flutter SDK

I just tried to execute Flutter: New Project, but it shows an error that could not find a flutter SDK.
I've ensured to complete all of the requirements from the flutter doctor.
Is there any way to solve this problem?
Thanks.
On macOS this was solved by following these steps.
First find where you downloaded the flutter sdk (Can be downloaded from here). It should be in your downloads folder unless you selected somewhere else.
Next:
Open up Terminal. Run the following command: sudo nano /etc/paths
Enter your password, when prompted.
Go to the bottom of the file, and enter the path you wish to add.
Hit control-x to quit.
Enter “Y” to save the modified buffer.
If the sdk is downloaded into your Downloads folder, your path to add should be /Users/yourusername/Downloads/flutter/bin
Lastly, quit and restart your terminal windows and VS Code. After restarting, both apps should recognize flutter and running flutter doctor should now work.
If you installed Flutter extension please restart VS_CODE and try it again. I already had the same problem.
The thing is VSCode looks for .packages file in your Flutter project this file contains path to your Flutter SDK & some other metadata. You're getting this error because either the .packages file is missing or either the path to Flutter SDK in .packages file contains some discrepancies.
To resolve it, you can;
Either edit the .packages file & set the path.
Or if you already have a working Flutter project then a .packages must've been already created. Copy that file & paste it in the root directory of your project.
Restart VSCode & run flutter pub get
This should resolve the issue.
Check your environment variables:
Look for the PATH if it exists append the full path to flutter\bin
using ; as a separator from existing values.
If it does not exist, create a new user variable named PATH with the
full path to flutter\bin as its value.
And check the installation guide
After doing this:
Open VS Code.
Press Ctrl + Shift + P.
Then type flutter and select run flutter doctor it should be fixed now.
Create a new project to make sure it's run.
For Linux Users
For future visitors :)
I had the same problem, in my Terminal flutter doctor or in general flutter was recognized, but VSCode couldn't recognize my SDK location so flutter doctor for instance didn't work.
The first thing to do is to follow the steps in flutter documentation: Flutter Doc
If it didn't work, change the environment variables directly.
sudo nano /etc/environment
Now add the location of the bin folder of your flutter SDK, The folder that you downloaded from here.
For example, you extracted it here: /Home/User/Software
Add /Home/User/Software/flutter/bin to the PATH variable. Paths are separated by a colon(:)
After a few solutions I tried, this one worked.
For Windows
Open Visual Studio Code
Click Locate SDK
Find your flutter folder
Click Save
Re-open your Visual Studio Code
Press Ctrl + Shift + P
Type flutter and choose Flutter: New Application Project
Type your project name (e.g: flutter_application_1)
Select a folder to create the project in
If you want to change your flutter sdk location
Go to Visual Studio Code > Manage > Setting (or with shortcut Ctrl
Search dart
Find [dart] configure setting to be overriden for [dart] language
Click Edit in settings.json
You'll see :
{
"dart.sdkPath": "C:\\tools\\dart-sdk",
"dart.flutterSdkPath": "C:\\tools\\flutter",
"[dart]": {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.suggest.insertMode": "replace"
}
}
Replace dart.sdkPath and dart.flutterSdkPath with your new sdk location
Installing Flutter on Linux is a breeze using snapd as is documented officially. But then trying to create a Flutter project by following the official steps as mentioned here - Test drive - Flutter will throw an error similar to the description provided in the question.
On a side note though, you don't have to bother adding Flutter to PATH if it was installed using snapd.
Rather, follow these steps:
flutter create <insert_app_folder_name>
cd <insert_app_folder_name>
code .
What it really does is:
The Flutter binary is called from within snapd & creates a project with a directory name you provide.
You can now cd into that specific directory.
Call VSCode in the current directory which opens a VSCode instance within the project directory.
Refer to the answer by #maheshmnj about the .package. This file was created by Flutter earlier if you followed the aforementioned steps.
This means the Flutter extension couldn't find the Flutter SDK automatically (eg. by looking in your PATH or a path configured with dart.flutterSdkPath). Clicking Locate SDK should let you browse to the SDK manually and record that location for the next time. If you see this again after restarting, that's definitely a bug in the Dart/Flutter extension, so please open an issue at https://github.com/Dart-Code/Dart-Code and include the output from clicking the Show Log button, as well as noting whether there's a dart.flutterSdkPath setting in your VS Code User Settings.
If you have just installed the flutter extension, close all the vs code applications running and restart the vs code then it will work as expected.
In order to run a new flutter project,
Go to vs code-> View tab -> command pallette -> select Flutter ->
give a name to the project ->give the path of the project
Now you are good to go with flutter.
I would like to complete NoobN3rd information.
In VSCode Linux I used this steps:
sudo nano /etc/environment
Type your password
I added 3 paths at the end of line:
3.1 /"flutter instalation directory"/flutter/bin
3.2 /"flutter instalation directory"/flutter/packages
3.3 /"flutter instalation directory"/flutter/dev
Save it and reboot your system
Look at my environment file to have an example:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/paulo/development/flutter/bin:/home/paulo/development/flutter/packages:/home/paulo/development/flutter/dev"
if youknow where have you extracted your zip file of dart(Eg. at the time of extraction i setup the path C:\src\flutter)
then in vs code goto
c drive
-src
-flutter
-bin
-cache
-(dart-sdk)
select this folder and your
vs code will be adjusted.
I was facing the same problem. I've initially followed all the steps provided by installation guide of Flutter and was able to run an existing project using flutter run command.
So I've tried again repeating the very same steps of the installation guide and changed the path that I initially set like:
export PATH="$PATH:~/path/to/flutter/bin"
For one like:
export PATH="$PATH:/home/user/path/to/flutter/bin"
Then I run source ~/.bashrc and restarted Visual Code and worked! so I suppose that it was something related to ~ in the path.
I would like to add a complementary and alternative response to the Linux solutions given by NoobN3rd, Traufvihal and Paulo Ravaiano.
I'm using Manjaro and for some reason my Visual Studio Code was not picking up all the environment variables definition. I tried all the solutions and finally I realised the problem was not with the variables definition (my final solution contains them all in ~/.bashrc but it should work with /etc/environment as well) but on how Visual Studio Code was launched.
In case someone else is facing this problem, I noticed that running VS Code from the applications menu fails to link the environment variables for some reason. On the other hand, launching "code-oss" from the terminal does the trick and picks all my variables defined in my ~/.bashrc file.
Hope it helps!
I just got out of the same trouble, after numerous hit and trials trying to run flutter commands from vs code terminal the below set of steps got the things up for me.
In Ubuntu 18.04
Grab the path of the directory where flutter was unpacked by you.Mine was in the Home directory for the root user. Location can be any of your choice.
Go to the Home for your root user
Un-hide all of the hidden files in this directory.
Look for .bashrc file. Do not look for .profile file.
Open .bashrc file using nano/vim/text editor which ever you like.
Scroll to the bottom of the file and add this line -
export PATH="$PATH:pwd/flutter_linux/flutter/bin"
Quit all instances of the vscode (if any) opened.
Re-open and in the terminal type which flutter
Here -
I had re-named the un-zipped folder name like "flutter_linux_v1.12.13+hotfix.9-stable" with "flutter_linux"
Hope this helps......
i was also facing this error, after putting the flutter sdk path at the End of the PATH variable(not in middle or start) it works fine for me
For those who want to change their Flutter SDK path for the Dart & Flutter plugin
Click on Manage Icon(on Mac)
Click on Settings
On the Settings page, Click on Dart & Flutter.
Look for Dart: Sdk Path, click on Edit in settings.json
Edit dart.flutterSdkPath to your VSCode Flutter path
For me non of the answers helped.
What helped was (on macOS) opening the .bash_profile file via
sudo nano .bash_profile
and change the path to where my Flutter was as this has changed. Or add this line export PATH="$PATH:/home/user/path/to/flutter/bin"
hope this helpes.
QUICK SOLUTION!: If on macOS, PLUS everything had been working flawlessly previously, and this happens all of a sudden, or periodically, here is what I eventually discovered...
If your mac restarted, either on its own due to a crash, freeze or overnight install of updates, and VS Code was running, it generally restores all your vscode instances, but with various environment-related errors such as this one. The reason is that you are not running in the context of a shell and you don't have access to those environment settings. See this article from the VS Code documentation.
THE SOLUTION?: Quit and restart VS code as you normally would. Others have mentioned this, but I thought it would be good to know why this happens so you aren't surprised next time.
Please refer to the Get Flutter SDK section and locate where you have installed your flutter\bin folder. In my case, I put the flutter bin in my Documents folder.
See the following image Flutter\bin location
Windows
After make sure right Flutter version is in your path: https://docs.flutter.dev/get-started/install/windows
and you can run flutter doctor successfully
in VS Code you need to go to File->Preferences->Settings (or Ctrl+,)
then search for dart.flutterSdkPath then click on "Edit in settings.json" make sure it is the right path there.
I had the same problem, the solution was:
take the folder where you have extracted your zip file (for example: C:\src\flutter\flutter) then put it in the environment variable path and restart vscode.

Flutter doctor hangs on start, no output

I'm trying to install Flutter on my Windows 8 computer. I unzipped files to C:/flutter and added the bin folder to the path variable. However I am stuck on the step where I have to run flutter doctor in flutter_console. The Flutter doctor hangs and only shows the blinking cursor and no output. More interestingly any other flutter command will freeze the exact same way.
I have already tried
Running flutter console as admin
Reinstalling flutter
Installing the dev version
Use the VS code plugin to run flutter doctor
But they all led to the same result
So the solution of this issue is:
delete folder in your flutter SDK path flutter/bin/cache (detail info here)
run flutter doctor -v again will trigger downloading Dart SDK
PS: if your network is slow because of in china, check bellow:
Do things bellow in terminal maybe speed up your the download speed (for me it's speed up 3x) for changing channel:
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn (detail info here)
flutter channel stable (one example of change flutter channel)
flutter doctor -v (trigger downloading SDK)
Albeith in win10, these steps solved the issue for me (do not know if all are necessary)
restart win
run cmd as administrator
flutter doctor
According to this git issue, this is mostly caused by installing flutter in a directory for which you do not own the priviledges. For example, the Program Files folder: to solve then, you can try to move the installation folder
Problem
I had the same problem while trying to reinstall flutter using the recommended windows install guide found here https://docs.flutter.dev/get-started/install/windows
(flutter_windows_3.3.9-stable).
All flutter commands would hang and only show the flashing cursor. It did not matter if I was in the flutter console, PowerShell, VS Code terminal or Admin Command prompt.
This made running flutter doctor impossible, and thus I couldn't complete the flutter setup.
Environment
I am using a PC running Windows 10.
I am located in North America. (If you are in China, you may need to use a proxy server for the initial download).
Flutter was installed on a drive with ample free space in a non-restricted folder.
I have a stable internet connection.
I have git for windows installed and have set up my ssh keys. (you can download and install this form here https://git-scm.com/download/win).
I have my Windows Firewall and network protection on. (You may need to turn off third party firewalls or add a rule to them allowing flutter to make connections to the internet during the flutter setup).
Solution
This solution worked for me and should resolve most install problems related to installing flutter on a Windows environment.
Please upvote if it works for you.
Step 0 - Remove flutter from system:
If reinstalling flutter, do this step, otherwise move to step 1 if preforming a fresh installation.
Open file explorer and delete the folder titled flutter if already installed.
Type environment variables into the windows search bar and open Edit the system environment variables.
Click environment variables in the Advanced tab.
Double-click the word Path found under User variables for {YOUR USER NAME}.
Select any entries that end with \flutter or \flutter\bin and delete them.
Click the Ok button and then the Ok button to apply the changes.
Step 1 - Download Stable Flutter Version:
Go to the official flutter website https://docs.flutter.dev/development/tools/sdk/releases and download the most recent flutter version in the Stable channel (Windows).
Once downloaded, unzip the folder.
Place the flutter folder found inside the Zip file wherever you would like to store it on your computer. Flutter recommend putting it in C:\src\flutter. You can place it where've you like as long as It's not in a folder that requires elevated privileges to access, such as the C:\Program Files\ folder.
Note* I used Windows Explorer to unzip the file, however others report used 7-Zip file Manager for unzipping solved their problem.
Step 2 - Setup Environment Variables:
Type environment variables into the windows search bar and open Edit the system environment variables.
Click environment variables in the Advanced tab.
Double-click the word Path found under User variables for {YOUR USER_NAME}.
Click Browse... and navigate to where you placed the flutter folder. Then navigate to the bin file inside the flutter folder and click ok.
A new environment variable should have been added that looks like C:\src\flutter\bin.
You also need to make sure Git\bin\cmd, Git\bin\git.exe and, C:\Windows\System32\WindowsPowerShell\v1.0\ system environment paths are setup. These were post likely configured during your git for windows install.
Follow the "Update your path section" found here https://docs.flutter.dev/get-started/install/windows if this doesn't work for you.
Note* If Path doesn't exist, click new... and set variable name to Path and Variable value to the file path of your bin folder found in the flutter folder you just unzipped.
Step 3 - Reboot your computer in Safe Mode with Networking:
Press the Windows key + I on the keyboard to open Settings, or type settings in the windows search bar.
Click Update & Security and on the left pane select Recovery.
Under Advanced Startup, click Restart Now.
After the computer restarts, on the Choose an Option screen, select Troubleshoot > Advanced Options > Startup Settings > Restart.
After the computer restarts, a list of options appears. Select 5 or F5 for Safe Mode with Networking or whatever key your computer says to boot into Safe Mode with Networking.
Step 4 - Launch Administrator Command Prompt:
After rebooting, type command prompt into the windows search bar.
Right-click the application icon and click Run as administartor.
Run the following commands, flutter pub cache repair then flutter doctor -v. This might take quite some time if you have poor internet, as it will re-downloads every package in the cache.
If flutter doctor reports any red or yellow warnings with your environment, you need to resolve these first before continuing. These are quite common, and a Google search of the error or warning should solve your problem.
Note* if the command flutter is unrecognized, this means you didn't set up your environment path variables in step 2 correctly.
Step 5 - Reboot and run your project
Now that flutter doctor has run in safe mode, we can restart the computer and get out of safe mode.
Open your flutter project in Visual Studio Code.
Open a terminal window under terminal > new Terminal.
run the command, git config --global --add safe.directory C:/src/flutter make sure you use forward / and set the file path to wherever you saved your flutter folder. This can also be run from the administrator command prompt if you don't have VS Code or a flutter project.
Then run flutter doctor -v in the VS Code terminal to make sure everything is working.
Now we need to rebuild all of our packages and dependencies, run the following list of commands in order.
flutter clean
flutter pub cache repair
flutter pub get
flutter pub upgrade --major-versions
Troubleshooting
These are other solutions I noticed on stack overflow while trying to solve the problem for myself. These didn't work for my situation, but may help you solve yours.
Flutter doctor, running very slowly. Try deleting the cache folder found in, C:\src\flutter\bin\cache\ then running flutter doctor -v again. Flutter doctor hangs on start, no output
If you are in China. Download flutter through a mirror site.
Try installing a different type of unzip program (like 7-zip).
Make sure you are using the Stable flutter channel.
Make sure your path variables are set up correctly.
getting error "Waiting for another flutter command to release the startup lock" Use task manager to forcibly close any flutter or dart programs.
Can't delete old flutter folder, in use for some reason. Restart and immediately delete the folder.
Make sure flutter isn't installed in a folder that requires admin privileges to access, such as C:\Program Files\.
Make sure you have git for windows installed and have set up your ssh keys.
Add the Flutter and Dart extensions to VS Code.
Add the flutter and Dart plugins to Android Studio.
Delete the cache folder inside bin folder of the flutter sdk then run flutter doctor it should work now.