在嵌入式Linux设备上使用Flutter开发图形界面(试水)

这篇具有很好参考价值的文章主要介绍了在嵌入式Linux设备上使用Flutter开发图形界面(试水)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

安装Docker

链接: https://www.bilibili.com/video/BV1qE411N7aC/?spm_id_from=333.880.my_history.page.click&vd_source=0c443477abedebf2fdf7abecef55405d
我是跟着这个视频安装 Docker Desktop for Windows + 启用k8s
k8s网址
https://github.com/AliyunContainerService/k8s-for-docker-desktop

尝试交叉编译

主要步骤参照 https://www.toradex.com/zh-cn/blog/zai-qian-ru-shi-linux-she-bei-shang-shi-yong-flutter-kai-fa-tu-xing-jie-mian 网址的内容(写的很好~)

以下是我一路踩坑填坑的血泪史啦~~~~

首先一个ubuntu20.04容器

1、创建容器 flutter_build或再次进入容器

~$ docker pull ubuntu:20.04
~$ docker run -it -v /home/user/flutter:/opt/flutter --name flutter_build ubuntu:20.04 /bin/bash

上述的 /home/user/flutter是对应在本机上准备的路径,比如我在E:\workspace_E\Desker\flutter_docker新建了一个目录,即如下:

~$ docker run -it -v E:\workspace_E\Desker\flutter_docker:/opt/flutter --name flutter_build ubuntu:20.04 /bin/bash

即将E:\workspace_E\Desker\flutter_docker 映射到容器内的**/opt/flutter**下。

后续进入改容器重新编译,即输入以下命令:

~$ docker container start flutter_build
~$ docker exec -it flutter_build bash

flutter_build 就是之前创建时容器的名称,你可以在Docker看到。

2、安装所需软件

# apt update
# apt upgrade
# apt install clang cmake build-essential pkg-config libegl1-mesa-dev libxkbcommon-dev libgles2-mesa-dev
# apt install libwayland-dev wayland-protocols git curl wget unzip git
# apt install python2
# apt install virtualenv

3、下载编译工具

# mkdir -p /opt/flutter
# cd /opt/flutter
# git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
# export PATH=$PATH:$(pwd)/depot_tools

注意:如果

4、创建python2环境

默认的 ubuntu:20.04 使用 Python3,在容器里使用 virtualenv 创建 Python2 环境。

# virtualenv .env -p python2
# source .env/bin/activate

5、创建 .gclient文件并指定版本

# cat .gclient
solutions = [
{
  "managed": False,
  "name": "src/flutter",
  "url": "https://github.com/flutter/engine.git@bd539267b42051b0da3d16ffa8f48949dce8aa8f",
  "custom_deps": {},
  "deps_file": "DEPS",
  "safesync_url": "",
  "custom_vars" : {
    "download_android_deps" : False,
    "download_windows_deps" : False,
  },
},
]

上面的 bd539267b42051b0da3d16ffa8f48949dce8aa8f 对应 ${path_to_flutter_sdk_install}/flutter/bin/internal/engine.version,两者需要一致。如果不指定的话,会下载最新的版本。除非确实需要编译最新版本的 Engine,否则并不推荐。

我是这样做的:
进入 /opt/flutter 目录

$ cd /opt/flutter

然后使用 echo 命令和重定向操作符>来创建 .gclient文件并将第一行写入。

$ echo `solutions = ['>.gclient

然后 ls,你可以看到目录下已经生成了一个.gclient 文件
在本机对应的映射地址处用笔记本打开,直接复制上去保存即可。

最后,获取代码

$ gclient sync

6、编译embbedder

这里编译为arm64 目标 release 模式的 embedder

# cd src
# ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode release --embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples
# ninja -C out/linux_release_arm64

在这里,报了不少错,以下是解决方法:
1)

(.env) root@0e5187d0fb8b:/opt/flutter/src# ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode release --embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples
GOMA usage was specified but can't be found, falling back to local builds. Set the GOMA_DIR environment variable to fix GOMA.
Tried to download prebuilt Dart SDK but an appropriate version could not be found!
Either retry by running flutter/tools/download_dart_sdk.py manually or compile from source by setting `--no-prebuilt-dart-sdk` flag to tools/gn
Generating GN files in: out/linux_release_arm64
Traceback (most recent call last):
  File "./flutter/tools/gn", line 589, in <module>
    sys.exit(main(sys.argv))
  File "./flutter/tools/gn", line 581, in main
    gn_call_result = subprocess.call(command, cwd=SRC_ROOT)
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/opt/flutter/src/flutter/third_party/gn/gn'
User
(.env) root@0e5187d0fb8b:/opt/flutter/src# ninja -C out/linux_release_arm64
depot_tools/ninja.py: Could not find Ninja in the third_party of the current project, nor in your PATH.
Please take one of the following actions to install Ninja:
- If your project has DEPS, add a CIPD Ninja dependency to DEPS.
- Otherwise, add Ninja to your PATH *after* depot_tools.

解决方法:

$ apt-get update
$ apt-get install ninja-build
(.env) root@0e5187d0fb8b:/opt/flutter/src# ninja -C out/linux_release_arm64
ninja: Entering directory `out/linux_release_arm64'
ninja: error: loading 'build.ninja': No such file or directory

解决方法:
1、首先需要确定GN是否已经运行并成功生成了build.ninja。你可以通过在out/linux_release_arm64目录中运行ls命令来查看文件是否存在。
2、如果build.ninja文件不存在,需要运行GN来生成它。可以在src目录下运行如下的GN命令:

./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode release --embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples

这个命令告诉GN为ARM64架构的Linux生成Flutter Engine 的发布版。
3、运行完GN命令后,你应该可以在out/linux_release_arm64目录下看到build.ninja文件。这是,可以再次运行Ninja开始构建:

$ ninja -C out/linux_release_arm64
(.env) root@0e5187d0fb8b:/opt/flutter/src# ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode release --embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples
GOMA usage was specified but can't be found, falling back to local builds. Set the GOMA_DIR environment variable to fix GOMA.
Using prebuilt Dart SDK binary. If you are editing Dart sources and wish to compile the Dart SDK, set `--no-prebuilt-dart-sdk`.
Generating GN files in: out/linux_release_arm64
ERROR at //build/config/linux/pkg_config.gni:103:17: Script returned non-zero exit code.
    pkgresult = exec_script(pkg_config_script, args, "value")
                ^----------
Current dir: /opt/flutter/src/out/linux_release_arm64/
Command: python3 /opt/flutter/src/build/config/linux/pkg-config.py -s /opt/flutter/src/build/linux/debian_sid_arm64-sysroot -a arm64 freetype2
Returned 1.
stderr:

Traceback (most recent call last):
  File "/opt/flutter/src/build/config/linux/pkg-config.py", line 249, in <module>
    sys.exit(main())
  File "/opt/flutter/src/build/config/linux/pkg-config.py", line 144, in main
    prefix = GetPkgConfigPrefixToStrip(options, args)
  File "/opt/flutter/src/build/config/linux/pkg-config.py", line 82, in GetPkgConfigPrefixToStrip
    prefix = subprocess.check_output([options.pkg_config,
  File "/usr/lib/python3.8/subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pkg-config'

See //build/config/linux/BUILD.gn:30:1: whence it was called.
pkg_config("freetype2") {
^------------------------
See //build/config/BUILDCONFIG.gn:357:33: which caused the file to be included.
  _native_compiler_configs += [ "//build/config/linux:sdk" ]
                                ^-------------------------

解决方法:

$ apt-get update
$ apt-get install pkg-config
$ apt-get install libfreetype6-dev
GOMA usage was specified but can't be found, falling back to local builds. Set the GOMA_DIR environment variable to fix GOMA.
Using prebuilt Dart SDK binary. If you are editing Dart sources and wish to compile the Dart SDK, set `--no-prebuilt-dart-sdk`.
Generating GN files in: out/linux_release_arm64

上述表示已经成功地通过了 gn生成步骤。生成GN文件是构建过程的一部分,这些文件指导了下一步的构建过程。在这个步骤,你可能看到有关GOMA的警告,但你可以暂时忽略它,因为它主要用于加速构建过程。

接下来,可以运行下面的命令构建代码:

ninja -C out/linux_release_arm64

请注意,构建过程可能需要一些时间,并且可能会需要大量的磁盘空间。在构建完成后,你应该会在 out/linux_release_arm64 目录下看到你的构建结果。

ERROR at //build/config/linux/pkg_config.gni:103:17: Script returned non-zero exit code.
    pkgresult = exec_script(pkg_config_script, args, "value")
                ^----------
Current dir: /opt/flutter/src/out/linux_release_arm64/
Command: python3 /opt/flutter/src/build/config/linux/pkg-config.py -s /opt/flutter/src/build/linux/debian_sid_arm64-sysroot -a arm64 freetype2
Returned 1.

解决方法:
还是因为环境中没有找到pkg-config,

apt-get update
apt-get install pkg-config
apt-get install libfreetype6-dev

第二步创建一个arm64的容器

1、选择合适的镜像

在嵌入式Linux设备上使用Flutter开发图形界面(试水),Flutter,linux,flutter,运维
这是我选的镜像,其他的都尝试了几个都有不同程度的bug,有更好的话,请评论推荐哈~~

2、创建Container

首先同样在本机创建一个文件夹作为映射地址
在嵌入式Linux设备上使用Flutter开发图形界面(试水),Flutter,linux,flutter,运维

$ docker run -it -v E:\workspace_E\Desker\torizon\workspace:/opt/workspace torizon/arm64v8-debian-base /bin/bash

3、在容器中安装所需的软件

# apt update
# apt install clang cmake build-essential pkg-config libegl1-mesa-dev libxkbcommon-dev libgles2-mesa-dev
# apt install unzip git
# apt install curl wget
# apt install libwayland-dev wayland-protocols
# apt install libdrm-dev libgbm-dev libinput-dev libudev-dev libsystemd-dev

4、下载 flutter-embedded-linux代码

# cd /opt/workspace
# git clone https://github.com/sony/flutter-embedded-linux.git
# cd flutter-embedded-linux/
# mkdir build

5、编译生成 flutter-clientlibflutter_elinux_wayland.so两个文件

参照网址:https://github.com/sony/flutter-embedded-linux/wiki/Building-Embedded-Linux-embedding-for-Flutter

# cd build
# cmake -DUSER_PROJECT_PATH=examples/flutter-wayland-client -DCMAKE_BUILD_TYPE=Release ..
# cmake -DUSER_PROJECT_PATH=examples/flutter-wayland-client -DCMAKE_BUILD_TYPE=Release -DBUILD_ELINUX_SO=ON -DBACKEND_TYPE=WAYLAND -DENABLE_ELINUX_EMBEDDER_LOG=OFF -DFLUTTER_RELEASE=ON ..
# cmake --build .

很好,目前最大的坑来了,只生成了libflutter_elinux_wayland.so文件,并没有生成flutter-client文件~
正在找问题在哪里~~

第三步交叉编译

1、回到flutter_build容器

$ docker exec -it flutter_build bash

2、下载 ``flutter-elinux.

这个是Flutter SDK

$ cd /opt/flutter/
$ git clone https://github.com/sony/flutter-elinux
$ export PATH=$PATH:/opt/flutter/flutter-elinux/bin

运行下面命令查看安装情况

$ flutter-elinux doctor
$ flutter-elinux devices

3、创建一个示例工程

$ flutter-elinux create demo1
$ cd demo1

4、复制并打包

在本机上cmd上

$ docker ps -a

在嵌入式Linux设备上使用Flutter开发图形界面(试水),Flutter,linux,flutter,运维

$ docker cp ce88db40402c:/ arm64-sysroot
$ tar cvf arm64-sysroot.tar arm64-sysroot

注意打包的路径,找到 arm64-sysroot.tar 复制到 flutter_build 容器中。

5、解压

$ cd /opt/flutter
$ tar vxf arm64-sysroot.tar

6、编译

$ cd demo1
$ flutter-elinux build elinux --target-arch=arm64 --target-sysroot=/opt/flutter/arm64-sysroot --target-compiler-triple=aarch64-linux-gnu

编译结束查看 build/elinux/arm64/release/bundle,这里是 Flutter app 运行所需的所以文件。

$ tree build/elinux/arm64/release/bundle -L 2

在嵌入式Linux设备上使用Flutter开发图形界面(试水),Flutter,linux,flutter,运维
后面还在尝试中~~

相关资料查询
[1] https://github.com/sony/flutter-elinux/wiki/Building-flutter-apps#3-cross-building-from-x64-to-arm64;
[2]https://github.com/sony/flutter-embedded-linux/wiki/Building-Flutter-Engine-from-source
[3]https://github.com/sony/flutter-elinux/issues/140
[4]文章来源地址https://www.toymoban.com/news/detail-832705.html

到了这里,关于在嵌入式Linux设备上使用Flutter开发图形界面(试水)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 正点原子嵌入式linux驱动开发——U-boot图形化配置及其原理

    经过之前对uboot的学习可以知道: uboot可以通过stm32mp15_trusted_defconfig来配置,或者通过文件stm32mp1.h来配置uboot 。还有 另外一种配置uboot的方法,就是图形化配置 ,以前的uboot是不支持图形化配置,只有Linux内核才支持图形化配置。不过不知道从什么时候开始,uboot也 支持图形

    2024年02月07日
    浏览(33)
  • 嵌入式Linux系统中的设备驱动开发:从设备树到驱动实现

    大家好,今天给大家介绍 嵌入式Linux系统中的设备驱动开发:从设备树到驱动实现 ,文章末尾附有分享大家一个资料包,差不多150多G。里面学习内容、面经、项目都比较新也比较全! 可进群免费领取。 在嵌入式Linux系统中,设备驱动是连接硬件设备和操作系统之间的桥梁。

    2024年02月19日
    浏览(44)
  • 嵌入式Linux驱动开发——解决/sys/bus/spi/devices下没有对应的spi设备文件

    最近在学习Linux驱动开发中SPI总线的驱动框架,但在修改完设备树添加完对应的spi设备节点后,理应在/sys/bus/spi下会有对应的spi设备,我的目录下面没有。 无spi设备 然后我查看了/proc/device-tree,发现有对应的spi设备节点,我就先没有过多理会这个问题。 /proc/device-tree下有对应

    2024年02月16日
    浏览(34)
  • 实时嵌入式Linux设备基准测试快速入门3实时嵌入式Linux

    计算机系统与环境之间的交互通常是实时发生的,因此,对于作为计算机系统一部分的嵌入式设备来说,有关实时操作系统的讨论也是一个重要话题。 本章将讨论实时系统的特点,介绍在Linux嵌入式设备上实现实时性的主要方法。具体来说,本章将重点分析PREEMPT_RT内核补丁,

    2024年02月15日
    浏览(38)
  • 【嵌入式Linux内核驱动】04_Jetson nano GPIO应用 | 驱动开发 | 官方gpiolib、设备树与chip_driver

    0.暴露给应用层 应用 解决调试目录为空的问题 调试信息 1.最简读写文件(在/SYS下) 设备树 验证测试 编译文件 驱动 of_get_named_gpio_flags //获取设备树节点的属性 gpio_is_valid //判断是否合法 devm_gpio_request //申请使用gpio,并调用设置pinctrl device_create_file //根据设备树节点属性,创建

    2024年02月07日
    浏览(45)
  • 嵌入式开发,如何防止设备被抄袭?

    在国内做产品设计开发,很难避免被抄袭,被仿照。在没有形成技术壁垒之前,如何防止产品被抄袭是一个不可回避的问题。 常规设备主要的防护手段有: 专利保护 加密保护代码 授权校验 持续更新和改进 对于一些比较重要的技术发明或是创新,应该尽快申请专利。虽然目

    2024年02月08日
    浏览(47)
  • 嵌入式图形库开发绚丽界面(lvgl、emwin、awtk)

            早些年的单片机开发中,很多都是使用文字菜单界面,这种界面让人感觉非常的朴实无华,内容言简意赅,如果使用图形库进行开发,你的产品一下子就让别人觉得有点高级,更容易去接收它。对于现在来说,很多的嵌入式图形库都可以做出绚丽的界面,占用RAM小,

    2024年01月25日
    浏览(37)
  • 嵌入式linux设备网口带宽-测试方法

    iperf是一个基于Client/Server的网络性能测试工具,可以测试TCP、UDP和SCTP带宽质量,能够提供网络吞吐率信息,以及震动、丢包率,最大段和最大传输单元大小等统计信息,帮助我们测试网络性能,定位网络瓶颈。其中抖动和丢包率适应于UDP测试,二带宽测试适应于TCP和UDP。 一

    2024年02月10日
    浏览(31)
  • 嵌入式Linux(8):字符设备驱动--注册字符类设备

    杂项设备 注册杂项设备: 注销杂项设备: 字符类设备 文件:include/linux/cdev.h 步骤流程: 定义一个cdev结构体。 使用cdev_init函数初始化cdev结构体成员变量。 参数: 第一个:要初始化的cdev结构体 第二个:文件操作集: cdev-ops = fops;//实际就是把文件操作集写ops 使用cdev_add函数

    2023年04月22日
    浏览(39)
  • 使用Yocto进行嵌入式Linux开发3 Toaster

    我们已经知道了如何在Poky中使用BitBake构建图像image,那么我们将学习如何使用Toaster完成同样的操作。 Toaster是一个用于配置和运行构建的Web接口。它与BitBake和Poky构建系统通信,以管理和收集有关构建、软件包和镜像的信息。 使用Toaster的两种方法: 本地 可以将Toaster作为本

    2024年02月08日
    浏览(30)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包