Visual Studio Code调试Flutter报错“[CHROME]:need to run as root or suid”

在最新的 Ubuntu 22.04 系统上使用Visual Studio Code调试Flutter应用,Chrome使用Snap安装。

通过指定 CHROME_EXECUTABLE=/snap/bin/chromium,在调试的时候,报错如下:

Launching lib/main.dart on Chrome in debug mode...
lib/main.dart:1
[CHROME]:need to run as root or suid
Failed to launch browser after 3 tries. Command used to launch it: /snap/bin/chromium --user-data-dir=/tmp/flutter_tools.SEVTFD/flutter_tools_chrome_device.AMHTFX --remote-debugging-port=38457 --disable-background-timer-throttling --disable-extensions --disable-popup-blocking --bwsi --no-first-run --no-default-browser-check --disable-default-apps --disable-translate http://localhost:42407
Failed to launch browser. Make sure you are using an up-to-date Chrome or Edge. Otherwise, consider using -d web-server instead and filing an issue at https://github.com/flutter/flutter/issues.
Exited (sigterm)

解决方法就是指定真实的Chrome安装路径,直接调用,而不是通过Snap的沙箱,解决沙箱无法调试的问题。

如下:

#export CHROME_EXECUTABLE=/snap/bin/chromium
export CHROME_EXECUTABLE=/snap/chromium/current/usr/lib/chromium-browser/chrome

上述方法同样可以解决 Android Studio 在 Ubuntu 22.04 系统上无法找到 Chrome 的问题。

参考链接


How to get the snap-based chromium to access a separately mounted filesystem?

发布者

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注