gpt4 book ai didi

VSCode Can't Find the PATH To the Flutter SDK(VSCode找不到颤动SDK的路径)

转载 作者:bug小助手 更新时间:2023-10-25 23:30:58 26 4
gpt4 key购买 nike



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.

我刚刚试图执行Ffltter:New Project,但它显示了一个错误,找不到Ffltter SDK。我已经确保完成扑翼医生的所有要求。


enter image description here


enter image description here


Is there any way to solve this problem?

有什么办法可以解决这个问题吗?


Thanks.

谢谢。


更多回答

Locate SDK not Work ?

定位SDK不工作?

did you set the flutter sdk path ?

你有没有设置扑翼SDK的路径?

@AbhayKoradiya yup, locate SDK not work. i've been tried locate the SDK, once i restart my vscode, but it still same

@AbhayKoradiya是的,找到SDK不工作。我试着找到SDK,一旦我重启我的vscode,但它仍然是一样的

As the error suggests, set up your PATH environment and then start a new shell and from it open VSCode.

如错误所示,设置您的PATH环境,然后启动一个新的外壳并从中打开VSCode。

I got the very same issues with @baimWonk, still don't know how to fix

我在@baimWonk上遇到了同样的问题,仍然不知道如何修复

优秀答案推荐

On macOS this was solved by following these steps.

在MacOS上,这是通过以下步骤解决的。



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.

首先找到你在哪里下载的颤动SDK(可以从这里下载)。它应该在您的下载文件夹中,除非您选择了其他位置。



Next:

下一步:




  1. Open up Terminal. Run the following command: sudo nano /etc/paths

  2. Enter your password, when prompted.

  3. Go to the bottom of the file, and enter the path you wish to add.

  4. Hit control-x to quit.

  5. 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

如果SDK已下载到您的下载文件夹中,则您要添加的路径应该是/USERS/YourUserName/Downloads/Ffltter/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.

最后,退出并重新启动终端窗口和VS代码。重启后,两个应用程序都应该可以识别颤动,运行颤动医生现在应该可以工作了。



If you installed Flutter extension please restart VS_CODE and try it again. I already had the same problem.

如果您安装了颤动扩展,请重新启动VS_CODE,然后重试。我已经有了同样的问题。



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.

问题是,VSCode在你的颤动项目中寻找.Packages文件,这个文件包含你的颤动SDK的路径和其他一些元数据。之所以会出现此错误,是因为缺少.Packages文件,或者.Packages文件中的颤振SDK的路径包含一些差异。


To resolve it, you can;

要解决这个问题,你可以;



  1. Either edit the .packages file & set the path.

  2. 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.

  3. Restart VSCode & run flutter pub get


This should resolve the issue.

这应该可以解决问题。



For Windows

适用于Windows



  1. Open Visual Studio Code

  2. Click Locate SDK

  3. Find your flutter folder

  4. Click Save

  5. Re-open your Visual Studio Code

  6. Press Ctrl + Shift + P

  7. Type flutter and choose Flutter: New Application Project

  8. Type your project name (e.g: flutter_application_1)

  9. Select a folder to create the project in


If you want to change your flutter sdk location

如果您想更改颤动SDK的位置



  1. Go to Visual Studio Code > Manage > Setting (or with shortcut Ctrl

  2. Search dart

  3. Find [dart] configure setting to be overriden for [dart] language

  4. 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

将dart.sdkPath和dart.fltterSdkPath替换为新的SDK位置



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.

    查找路径(如果存在),使用;作为现有值的分隔符,将完整路径附加到FIFTER\bin。



  • If it does not exist, create a new user variable named PATH with the
    full path to flutter\bin as its value.

    如果不存在,请创建一个名为PATH的新用户变量,并将Ffltter\bin的完整路径作为其值。




And check the installation guide

并查看安装指南


After doing this:

完成此操作后:



  1. Open VS Code.

  2. Press Ctrl + Shift + P.

  3. Then type flutter and select run flutter doctor it should be fixed now.

  4. 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.

我也有同样的问题,在我的终端颤动医生或一般颤动被识别,但VSCode不能识别我的SDK位置,所以例如颤动医生不起作用。


The first thing to do is to follow the steps in flutter documentation: Flutter Doc

首先要做的是按照flutter文档中的步骤操作: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.

现在添加颤振SDK的bin文件夹的位置,也就是您从此处下载的文件夹。


For example, you extracted it here: /Home/User/Software

例如,您将其解压缩到以下位置:/Home/User/Software


Add /Home/User/Software/flutter/bin to the PATH variable. Paths are separated by a colon(:)

将/Home/User/Software/Ffltter/bin添加到PATH变量。路径之间用冒号(:)分隔


After a few solutions I tried, this one worked.

在我尝试了几个解决方案后,这个解决方案奏效了。



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.

正如官方文档所述,使用SnapD在Linux上安装Fighter轻而易举。但是,尝试按照此处提到的官方步骤创建颤振项目-测试驾驶-颤动将抛出一个类似于问题中提供的描述的错误。


On a side note though, you don't have to bother adding Flutter to PATH if it was installed using snapd.

不过,顺便说一句,如果Path是使用Snapd安装的,那么您不必费心将颤动添加到Path。


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.

参考@maheshmnj关于. package的回答。如果您遵循上述步骤,此文件是由Flutter在前面创建的。



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

Windows之后,确保正确的颤动版本在您的路径中:https://docs.flutter.dev/get-started/install/windows,您可以成功运行颤动医生


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.

在VS代码中,您需要转到文件->首选项->设置(或Ctrl+,),然后搜索dart.fltterSdkPath,然后单击“在settings.json中编辑”,确保它是正确的路径。



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.

这意味着Flutter扩展无法自动找到Flutter SDK(例如。通过查看PATH或使用dart.flutterSdkPath配置的路径)。单击Locate SDK应该可以让您手动浏览到SDK并记录下该位置以备下次使用。如果您在重新启动后再次看到此问题,这肯定是Dart/Flutter扩展中的一个错误,因此请在https://github.com/Dart-Code/Dart-Code上打开一个问题,并包括单击Show Log按钮的输出,以及注意VS Code User Settings中是否有dart.flutterSdkPath设置。



I would like to add a complementary and alternative response to the Linux solutions given by NoobN3rd, Traufvihal and Paulo Ravaiano.

我想对NoobNird、Traufvihal和Paulo Ravaiano提出的Linux解决方案增加一个补充和替代的回应。



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.

我使用的是Manjaro,但出于某种原因,我的Visual Studio代码没有获取所有环境变量的定义。我尝试了所有的解决方案,最后我意识到问题不在于变量定义(我的最终解决方案将它们全部包含在~/.bashrc中,但它应该也适用于/etc/Environment),而是关于如何启动Visual Studio代码。



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.

如果其他人也面临这个问题,我注意到由于某种原因,从应用程序菜单运行VS Code无法链接环境变量。另一方面,从终端启动“code-oss”就可以完成这个任务,并选择在我的~/.bashrc文件中定义的所有变量。



Hope it helps!

希望它能帮上忙!



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.

如果您刚刚安装了颤动扩展,请关闭所有正在运行的VS代码应用程序并重新启动VS代码,然后它将按预期工作。


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.

我想填写NoobNird信息。


In VSCode Linux I used this steps:

在VSCode Linux中,我使用了以下步骤:



  1. sudo nano /etc/environment



  2. Type your password



  3. 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


  4. 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"


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...

快速解决方案!:如果在MacOS上,加上以前一切都运行得天衣无缝,而且这种情况突然或定期发生,这是我最终发现的……


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.

如果您的Mac重新启动,无论是由于崩溃、冻结或夜间安装更新,并且VS Code正在运行,它通常会恢复您的所有vscode实例,但会出现各种与环境相关的错误,如下面的错误。原因是您没有在Shell的上下文中运行,并且您没有访问这些环境设置的权限。请参阅VS代码文档中的这篇文章。


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.

解决方案是:退出并像往常一样重新启动VS代码。其他人也提到过这一点,但我想知道为什么会发生这种情况会很好,这样你下次就不会感到惊讶了。



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)

如果您知道您在哪里解压了DART的压缩文件(例如,在解压时,我设置了路径C:\SRC\Ffltter),然后在VS代码中转到c驱动器-src-fltter-bin-cache-(dart-sdk)


select this folder and your
vs code will be adjusted.

选择这个文件夹,你的vs代码将被调整。



For Apple M2 and .zshrc bash profile :

对于Apple M2和.zshrc bash配置文件:


In my case, my problem was the relative path.

在我的例子中,我的问题是相对路径。


I changed the environment variable

我更改了环境变量


from :

出发地:


export PATH="$PATH:./flutter/bin"

to :

致:


export PATH="$PATH:$HOME/flutter/bin"

And all is fine.

一切都很好。



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"

导出路径=“$PATH:~/PATH/TO/FUTTH/BIN”



For one like:

对于像这样的人:



export PATH="$PATH:/home/user/path/to/flutter/bin"

导出路径=“$PATH:/HOME/USER/PATH/TO/FUTTH/bin”



Then I run source ~/.bashrc and restarted Visual Code and worked! so I suppose that it was something related to ~ in the path.

然后我运行源代码~/.bashrc并重新启动可视代码并工作!因此,我认为这是与道路上的~有关的东西.



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.

我刚刚摆脱了同样的麻烦,在无数次的点击和尝试后,试图从VS代码终端运行颤动命令,下面的一组步骤为我做了一些事情。


In Ubuntu 18.04

在Ubuntu 18.04中



  1. 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.

  2. Go to the Home for your root user

  3. Un-hide all of the hidden files in this directory.

  4. Look for .bashrc file. Do not look for .profile file.

  5. Open .bashrc file using nano/vim/text editor which ever you like.

  6. Scroll to the bottom of the file and add this line -



export PATH="$PATH:pwd/flutter_linux/flutter/bin"




  1. Quit all instances of the vscode (if any) opened.

  2. 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"

在这里-我将解压缩后的文件夹名称重新命名为“Ffltter_Linux_v1.12.13+hotfix.9-STRATE”,并加上了“Ffltter_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

我也面临着这个错误,在将Ffltter SDK路径放在路径变量的末尾(而不是在中间或开始)后,它对我来说很好



For those who want to change their Flutter SDK path for the Dart & Flutter plugin

适用于那些想要更改飞镖和颤动插件的颤动SDK路径的用户



  1. Click on Manage Icon(on Mac)

  2. Click on Settings

  3. On the Settings page, Click on Dart & Flutter.

  4. Look for Dart: Sdk Path, click on Edit in settings.json

  5. 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

对我来说,没有一个答案是有帮助的。帮助(在MacOS上)通过以下方式打开.bash_profile文件



  • 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.

希望这能有所帮助。



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.

请参考获取Ffltter SDK部分,并找到安装Ffltter\bin文件夹的位置。在我的例子中,我把扑翼垃圾箱放在了我的文档文件夹中。


See the following image Flutter\bin location

请参见下面的图像颤动位置



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.

取出解压压缩文件所在的文件夹(例如:C:\src\flutter\flutter),然后将其放入环境变量path中,然后重新启动vscode。



Step 1: Press "Locate SDK"

第1步:按“查找SDK”


Step 2: Select the folder "flutter" (Browse your files until you find it, it's the default name)

第二步:选择文件夹“Ffltter”(浏览你的文件直到找到它,这是默认名称)


Step 3: Inside the default flutter folder, select the "Bin" folder.

步骤3:在默认的颤振文件夹中,选择“Bin”文件夹。


Step 4: Things should work out at this point :)

步骤4:事情应该在这一点上得到解决:)


P.S. This worked on VS Code Editor (Windows 11)

附注:这在VS代码编辑器(Windows 11)上有效



I had this problem for a long time. I noticed I had a .vscode directory. I deleted (moved somewhere else) and it worked fine after that. Probably a mismatch between my original linux vsc project which was copied to windows OS vsc. I hope this helps.

我有这个问题很长一段时间了。我注意到我有一个.vscode目录。我删除了(移动到了其他地方),在那之后它运行得很好。可能是我最初的Linux vsc项目不匹配,该项目被复制到了Windows OS vsc。我希望这能帮到你。



In my MacOS M2, I modify .zprofile

在我的MacOS M2中,我修改了.zprofile


sudo nano .zprofile

export PATH="$PATH:[PATH_OF_FLUTTER_GIT_DIRECTORY]/bin"

Use Option+X > P > Enter to save change and leave nano.

使用Option+X>P>Enter保存更改并离开Nano。



I'm using fvm and apparently I've deleted the version that I'm depending on.
please check vscode's settings.json file and also the settings.json under the .vscode folder in your project, and see where dart.flutterSdkPath points at.

我正在使用FVM,显然我已经删除了我所依赖的版本。请检查vscode的settings.json文件以及项目中.vscode文件夹下的settings.json,并查看dart.fltterSdkPath所指向的位置。


更多回答

This is informative. I have observed that you can run flutter projects with out having the path to the flutter binary in the PATH variable. This is ideal when you have multiple flutter sdks installed in your system. As a side note: This works only when you already have a project set up when Flutter was already in path.

这是信息量很大的。我观察到,在PATH变量中没有指向颤动二进制文件的路径的情况下,您可以运行颤动项目。当您的系统中安装了多个颤振SDK时,这是理想的选择。作为附注:仅当您已经设置了一个项目,而颤动已经在路径中时,此操作才起作用。

"Click Locate SDK" Where is this at?

“点击定位SDK”这是在哪里?

This is really the only thing that worked for me, thanks (I also use Manjaro). Most probably this is related to Flatpak and its sandboxing.

这真的是唯一对我有效的方法,谢谢(我也使用Manjaro)。这很可能与Flatpak及其沙盒有关。

But even when I do this, with everything the same as you said, I still have the same problem?

但是,即使我这样做了,一切都和你说的一样,我仍然有同样的问题吗?

Please include paths into code tags ``

请在代码标签中包含路径``

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com