gpt4 book ai didi

VS Code does not show Chrome as device for Flutter(VS Code未将Chrome显示为Flutter的设备)

转载 作者:bug小助手 更新时间:2023-10-28 10:19:48 26 4
gpt4 key购买 nike



I install Flutter and VS Code in the following way:

我通过以下方式安装Ffltter和VS代码:


$ sudo snap install --classic code
$ sudo snap install --classic flutter
$ export CHROME_EXECUTABLE="/usr/bin/chromium"

$ flutter doctor -v
[✓] Flutter (Channel stable, 2.2.1, on Linux, locale en_AU.UTF-8)
• Flutter version 2.2.1 at /home/debian/snap/flutter/common/flutter
• Framework revision 02c026b03c (4 months ago), 2021-05-27 12:24:44 -0700
• Engine revision 0fdb562ac8
• Dart version 2.13.1

[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.


[✓] Chrome - develop for the web
• CHROME_EXECUTABLE = /usr/bin/chromium

[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Chromium 90.0.4430.212 built on Debian 11.0, running on Debian 11.0

! Doctor found issues in 2 categories.

Unfortunately, VS code does not show me chrome as device:

不幸的是,VS代码没有显示chrome作为设备:


enter image description here


What did I miss?

我错过了什么?


更多回答

I needed to add export CHROME_EXECUTABLE="/usr/bin/chromium" into ~/.bashrc. Now it works.

我需要将EXPORT Chrome_Executable=“/usr/bin/Chrome”添加到~/.bashrc中。现在它起作用了。

For me Its brave. adding export CHROME_EXECUTABLE="/snap/bin/brave" in home > ~/.bashrc solved the problem

对我来说,它很勇敢。在home >中添加导出CHROME_EXECUTABLE="/snap/bin/brave”~/.bashrc解决了这个问题

I leave link to answer that seems to be related and should solve/help here: stackoverflow.com/a/69205440/6229867

我留下了链接来回答似乎相关的问题,应该在这里解决/帮助:Stackoverflow.com/a/69205440/6229867

优秀答案推荐

TL;DR


Add the following line in ~/.profile file (or ~/.bash_profile in some distros) and re-login.

在~/.profile文件(或某些发行版中的~/.bash_profile)中添加以下行并重新登录。


export CHROME_EXECUTABLE="/usr/bin/chromium"

Long answer


For Flutter to be able to find a chromium-based browser other than google-chrome, you need to set $CHROME_EXECUTABLE environment variable to the path of that browser.

要使Ffltter能够找到除Google-Chrome之外的基于铬的浏览器,需要将$Chrome_Executable环境变量设置为该浏览器的路径。


The issue is where you set this variable.

问题在于您在哪里设置此变量。


When running Flutter manually from a command shell, like bash, the variable needs to be set in that shell session. This can be achieved by just running the export command beforehand, or, as I had wrongly done it, by adding it to your shell's configuration file (e.g. ~/.bashrc).

当从命令外壳(如bash)手动运行Ffltter时,需要在该外壳会话中设置该变量。这可以通过预先运行EXPORT命令来实现,或者像我错误地那样,通过将其添加到您的外壳的配置文件中(例如~/.bashrc)。


However, VS Code does not execute flutter via an interactive shell. So files like .bashrc do not get executed in this case. As a result, any logic you've set up there, like exporting $CHROME_EXECUTABLE or extending $PATH, is ignored.

但是,VS代码不会通过交互式外壳执行颤动。因此,像.bashrc这样的文件在这种情况下不会执行。因此,您在那里设置的任何逻辑,如导出$Chrome_Executable或扩展$PATH,都将被忽略。


To confirm this, you can execute >Flutter: Run Flutter Doctor in VS Code's Command Palette (Ctrl+Shift+P). The output will show that in VS Code's context, Flutter doesn't see the $CHROME_EXECUTABLE set:

要确认这一点,您可以在VS代码的命令调色板(Ctrl+Shift+P)中执行>颤动:运行颤动医生。输出将显示,在VS代码的上下文中,Ffltter没有看到$Chrome_Executable集合:


[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

The solution is to define environment variables correctly, rather than only for interactive shells. Ways of doing this are different between Linux distributions. In Arch Linux, what worked for me was to put them in ~/.bash_profile instead of ~/.bashrc. Note that for changes to this file to take effect, you need to re-login into your system. In Ubuntu, ~/.profile might need to be used instead.

解决方案是正确定义环境变量,而不仅仅是为交互外壳定义环境变量。在不同的Linux发行版中,实现这一点的方法是不同的。在Arch Linux中,对我起作用的是将它们放在~/.bash_profile中,而不是~/.bashrc中。请注意,要使对此文件的更改生效,您需要重新登录到系统。在Ubuntu中,可能需要使用~/.profile。


For excellent quick explanation on the differences between configuration files, see this answer and others below it.

有关配置文件之间的差异的出色快速解释,请参阅此答案和下面的其他答案。


更多回答

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