You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Ubuntu 22.04树莓派4上运行Flutter Hello World遇空白屏及Gdk错误求助

在树莓派4 Ubuntu 22.04上运行Flutter Hello World空白屏+Gdk-CRITICAL错误的解决方法

问题描述

在搭载Ubuntu 22.04.2 LTS 5.15.0-1034-raspi系统的树莓派4上,使用Flutter snap包自带的Hello World示例构建运行时出现空白屏,终端同时输出Gdk-CRITICAL **: gdk_window_get_state: assertion 'GDK_IS_WINDOW (window)' failed错误。已尝试禁用Wayland并重启Gnome,但未解决问题。

运行命令及输出

drongopi1@drongopi1:~/snap/flutter/common/flutter/examples/hello_world$ flutter run -d linux
Launching lib/main.dart on Linux in debug mode...
Building Linux application...                                           

(hello_world:5130): Gdk-CRITICAL **: 16:05:51.404: gdk_window_get_state: assertion 'GDK_IS_WINDOW (window)' failed
Syncing files to device Linux...                                   388ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on Linux is available at: http://127.0.0.1:40529/ilbmD5GIboo=/
The Flutter DevTools debugger and profiler on Linux is available at:
http://127.0.0.1:9100?uri=http://127.0.0.1:40529/ilbmD5GIboo=/

Flutter Doctor输出

drongopi1@drongopi1:~$ flutter doctor -v
[✓] Flutter (Channel master, 3.13.0-17.0.pre.80, on Ubuntu 22.04.2 LTS
    5.15.0-1034-raspi, locale en_IN)
    • Flutter version 3.13.0-17.0.pre.80 on channel master at
      /home/drongopi1/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c11ac7be9a (57 minutes ago), 2023-08-07 05:43:32 -0400
    • Engine revision b10891e0d8
    • Dart version 3.2.0 (build 3.2.0-41.0.dev)
    • DevTools version 2.26.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 (Cannot find Chrome executable at
    google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[!] 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)
    • Linux (desktop) • linux • linux-arm64 • Ubuntu 22.04.2 LTS
      5.15.0-1034-raspi

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 3 categories.

解决步骤

1. 切换到Flutter稳定版

当前使用的是master开发分支,兼容性问题概率更高,切换到稳定频道:

flutter channel stable
flutter upgrade

之后重新构建运行项目。

2. 安装树莓派ARM架构专属依赖

虽然Linux工具链显示正常,但ARM平台可能需要额外依赖:

sudo apt install libgtk-3-dev libayatana-appindicator3-dev

3. 彻底强制使用X11会话

之前的Wayland禁用操作可能未生效,按以下步骤配置:

  • 编辑GDM配置文件:
sudo nano /etc/gdm3/custom.conf
  • 找到#WaylandEnable=false行,删除前面的#注释,保存退出。
  • 重启GDM服务:
sudo systemctl restart gdm3

重启后通过echo $XDG_SESSION_TYPE确认会话类型为x11。

4. 清理缓存后重建项目

缓存损坏可能导致渲染异常:

flutter clean
flutter pub get
flutter run -d linux

5. 尝试运行Release版本

Debug模式可能存在渲染兼容问题,构建并运行Release版:

flutter build linux --release
./build/linux/arm64/release/bundle/hello_world

内容的提问来源于stack exchange,提问作者Arki99

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 17:18:09