如何在Android Studio中,在Flatpak版 Chromium浏览器里运行Flutter应用?

移动开发 2026-07-11

我的环境如下

  • Android Studio,通过系统软件包管理器安装(在Arch Linux上是Pacman)
  • Ungoogled Chromium,通过Flatpak安装

现在我想在Ungoogled Chromium中从Android Studio启动一个Flutter应用。不过,在顶部栏的下拉菜单中我不能选择Chrome。只显示“Linux (desktop)”,而这个我用不了,因为该项目没有为它做好设置。

Flutter doctor的输出如下:

> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.41.4, on Arch Linux 6.19.8-arch1-1, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✗] Linux toolchain - develop for Linux desktop
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
[✓] Connected device (1 available)
[✓] Network resources

! Doctor found issues in 2 categories.

Flutter需要一个Chrome可执行文件,而不是一个命令。但我不能直接指定一个chrome的可执行文件,因为它在Flatpak里运行。我该如何处理这个?

解决方案

我们可以通过创建一个shell脚本来变通这个必需的可执行文件

#!/usr/bin/env bash
flatpak run io.github.ungoogled_software.ungoogled_chromium "$@"

把它创建在一个对你有用的位置,然后让它可执行。我把它命名为“chromium”。然后把环境变量设置为该脚本的位置

chmod +x chromium
export CHROME_EXECUTABLE="/my/path/to/chromium"

再次运行 flutter doctor,它应该就能识别到了。

> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.41.4, on Arch Linux 6.19.8-arch1-1, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[✓] Chrome - develop for the web
[✗] Linux toolchain - develop for Linux desktop
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 1 category.

现在我们需要让环境变量保持持久。根据你启动Android Studio的方式,方法会有差异。如果你是通过开始菜单启动(也就是通过一个 .desktop 文件),你可以简单地把以下行添加到 ~/.local/share/applications/android-studio.desktop

Exec=env CHROME_EXECUTABLE=/my/path/to/chromium android-studio %f

关闭Android Studio并通过开始菜单重新启动后,右上角会出现“Chrome (web)”配置。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章