安装snap再安装flutter再安装localsend@Ubuntu(FreeBSD下未成功)

时间:2024-03-20 10:58:40

Localsend介绍

localsend是一个跨平台的文件传送软件,可以在Windows、MacOS、Linux、Android和IOS下互相传送文件,只要在同一个局域网即可。

localsend官网:LocalSend

尝试安装localsend,发现需要使用flutter, 安装flutter发现需要snap,于是先安装snap

ubuntu下:apt install snapd

FreeBSD下:pkg install snap (失败,FreeBSD下的软件包并不是我们需要的)

snap介绍

Snap软件包是一种新型的Linux包管理工具,它采用了容器的概念,使得每个应用程序都拥有自己独立的文件和库,从而解决了应用程序之间的依赖问题,使得应用程序更易于管理。

Snap软件包的主要特点是自包含性和跨平台性。每个Snap软件包都包含了应用程序及其所有依赖项,这意味着用户无需担心依赖关系的问题,只需安装Snap软件包即可轻松使用应用程序。此外,Snap软件包的设计也考虑了跨平台性,使得同一个Snap软件包可以在不同的Linux发行版上运行,从而提高了软件的可移植性。

是在FreeBSD使用linux兼容安装的ubuntu,刚开始使用apt install snap安装没成功,以为就不支持。后来发现要使用apt install snapd 来安装就可以了。

兼容模式下除了最后不能使用Xwindows,其它跟普通ubuntu一模一样。

在ubuntu@FreeBSD安装snap

apt install snapd

Flutter介绍

Flutter 是谷歌的移动 UI 框架,可以快速在 iOS 和 Android 上构建高质量的原生用户界面。Flutter 支持跨平台、原生、开源免费,具有响应式框架、富有表现力和灵活的UI,以及跨平台自绘引擎等特点。

flutter官网文档:选择你的开发平台,开始使用 | Flutter 中文文档 - Flutter 中文开发者网站 - Flutter

 用snap安装flutter

sudo snap install flutter --classic

然后配置中文地址(国内加速):

export PUB_HOSTED_URL="https://pub.flutter-io.cn"

export FLUTTER_STORAGE_BASE_URL="https://storage.flutter-io.cn"

然后flutter doctor ,看到提示:

Telemetry is not sent on the very first run. To disable reporting of telemetry,
run this terminal command:

    flutter --disable-analytics

这样就算是安装好了。但是后面碰到很多小坑,所以再详细记录一下。

安装flutter详细步骤

官方手册:在中国网络环境下使用 Flutter | Flutter 中文文档 - Flutter 中文开发者网站 - Flutter

直接到官网下载flutter tar包,解压后发现可以使用

tar -xvf flutter_linux_3.19.3-stable.tar.xz 
cd flutter
./bin/flutter 

在.profile文件中最后一句加入路径,这样就可以直接使用flutter命令了

PATH="$PATH:/home/linuxskywalk/tools/flutter/bin"

 也可以在.shrc文件中加入:

set PATH=/home/skywalk/download/flutter/bin:$PATH

 按照flutter手册,加入环境变量配置:

# 将 PUB_HOSTED_URL 设置为镜像站点。

 export PUB_HOSTED_URL="https://pub.flutter-io.cn"

# 将 FLUTTER_STORAGE_BASE_URL 设置为镜像站点。

 export FLUTTER_STORAGE_BASE_URL="https://storage.flutter-io.cn"

 如果不加,国内是无法自动下载软件的。

配置好后flutter后,开始安装localsend

编译安装localsend

下载localsend,解压缩。刚开始是从官网下载压缩文件,后来也尝试了git下载源代码:git clone https://github.com/localsend/localsend

然后到localsend/app 目录(~/tools/localsend-1.14.0/app),执行:

flutter build linux

如果没有报错,就算成了!

但是有报错,详见调试部分,开始一步步解决报错问题。。

首先:

使用flutter doctor查找问题

发现linux部分有3个问题,按照提示安装三个软件包:

执行

sudo apt install libgtk-3-dev clang ninja-build 

后面build还有报错,根据提示安装下面两个库,解决build问题:

sudo apt install libappindicator3-1 libappindicator3-dev

还有报错需要修改文件:

修改pubspec.yaml文件

参考:https://github.com/fluttercandies/flutter_photo_manager/issues/1021

Adding this to pubspec.yaml worked as temporary fix, ty @den0206

dependency_overrides: 
  photo_manager: ^3.0.0-dev.2

当前还存在的问题:

flutter build linux 之后报错,见最后一个调试问题。

目前没有解决。

=====================================

解决问题的分界线

后来才明白,原来pubspec.yaml文件那里少修改了一个地方,

还需要修改这里:

dependencies:
  wechat_assets_picker: ^8.9.0-dev.1

修改之后,再run,有报错:

(localsend_app:253856): Gtk-WARNING **: 11:39:19.837: cannot open display

这其实证明基本已经成功了。只是没有窗体报错罢了。

进入xwindows窗口,再执行flutter run ,哇,localsend 终于成功运行了!

android版本,直接下载:https://github.com/localsend/localsend/releases/download/v1.14.0/LocalSend-1.14.0.apk

windows版本,直接下载:https://github.com/localsend/localsend/releases/download/v1.14.0/LocalSend-1.14.0-windows-x86-64.exe

总结:

localsend是一个非常不错的文件传送软件,只是在linux安装的时候,需要修改少量代码,增加了一定难度。

调试

编译flutter报错

 flutter build linux
Resolving dependencies... (1:42.1s)
Git error. Command: `git clone --mirror https://github.com/Tienisto/tray_manager.git /home/linuxskywalk/.pub-cache/git/cache/tray_manager-ad808f1c5d07229907508d5b7c74bd2e20923421`
stdout:
stderr: Cloning into bare repository '/home/linuxskywalk/.pub-cache/git/cache/tray_manager-ad808f1c5d07229907508d5b7c74bd2e20923421'...
fatal: unable to access 'https://github.com/Tienisto/tray_manager.git/': Failed to connect to github.com port 443: Connection timed out
exit code: 128

换用国内镜像

flutter doctor报错

[✗] Linux toolchain - develop for Linux desktop
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang), or
      can be downloaded from https://releases.llvm.org/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install
      ninja-build), or can be downloaded from
      https://github.com/ninja-build/ninja/releases
    ✗ GTK 3.0 development libraries are required for Linux development.
      They are likely available from your distribution (e.g.: apt install
      libgtk-3-dev)

根据linux部分的报错,

执行:sudo apt install libgtk-3-dev clang ninja-build

flutter build报错 because localsend_app depends on path 1.8.3,

$ flutter build linux
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you
trust this source!
Resolving dependencies... (3.8s)
Note: path is pinned to version 1.9.0 by flutter_localizations from the flutter SDK.
See https://dart.dev/go/sdk-version-pinning for details.


Because localsend_app depends on flutter_localizations from sdk which depends on
  path 1.9.0, path 1.9.0 is required.
So, because localsend_app depends on path 1.8.3, version solving failed.


You can try the following suggestion to make the pubspec resolve:
* Try upgrading your constraint on path: flutter pub add path:^1.9.0

按照提示执行:flutter pub add path:^1.9.0

这里失误了,应该是:flutter pub add path:^1.8.3

新报错The `system_tray` package requires ayatana-appindicator3-0.1 or appindicator3-0.1.

$ flutter build linux
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you
trust this source!

CMake Error at flutter/ephemeral/.plugin_symlinks/system_tray/linux/CMakeLists.txt:29 (message):


  The `system_tray` package requires ayatana-appindicator3-0.1 or
  appindicator3-0.1.


Building Linux application...     

Adding this to pubspec.yaml worked as temporary fix, ty @den0206

解决问题方法,执行:sudo apt install libappindicator3-1 libappindicator3-dev

报错:Error: Type 'DecoderCallback' not found.

flutter build linux
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you
trust this source!

ERROR: ../../../.pub-cache/hosted/pub.flutter-io.cn/photo_manager-2.8.1/lib/src/internal/image_provider.dart:71:5: Error: Type 'DecoderCallback' not found.
ERROR:     DecoderCallback decode, // ignore: deprecated_member_use
ERROR:     ^^^^^^^^^^^^^^^
ERROR: ../../../.pub-cache/hosted/pub.flutter-io.cn/photo_manager-2.8.1/lib/src/internal/image_provider.dart:96:5: Error: Type 'DecoderCallback' not found.
ERROR:     DecoderCallback decode, // ignore: deprecated_member_use
ERROR:     ^^^^^^^^^^^^^^^
ERROR: ../../../.pub-cache/hosted/pub.flutter-io.cn/photo_manager-2.8.1/lib/src/internal/image_provider.dart:71:5: Error: 'DecoderCallback' isn't a type.
ERROR:     DecoderCallback decode, // ignore: deprecated_member_use
ERROR:     ^^^^^^^^^^^^^^^
ERROR: ../../../.pub-cache/hosted/pub.flutter-io.cn/photo_manager-2.8.1/lib/src/internal/image_provider.dart:96:5: Error: 'DecoderCallback' isn't a type.
ERROR:     DecoderCallback decode, // ignore: deprecated_member_use
ERROR:     ^^^^^^^^^^^^^^^
ERROR: Target kernel_snapshot failed: Exception
Building Linux application...                                           
Build process failed

解决了这个问题,参见issue:About DecoderCallback cannot found error( Type 'DecoderCallback' not found.) · Issue #1021 · fluttercandies/flutter_photo_manager · GitHub

Adding this to pubspec.yaml worked as temporary fix, ty @den0206

dependency_overrides: 
  photo_manager: ^3.0.0-dev.2

重新在另一台机器做实验,发现报错: localsend_app depends on path 1.8.3,

 flutter build linux
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure
you trust this source!
Resolving dependencies... (12.7s)
Note: path is pinned to version 1.9.0 by flutter_localizations from the flutter SDK.
See https://dart.dev/go/sdk-version-pinning for details.


Because localsend_app depends on flutter_localizations from sdk which depends
  on path 1.9.0, path 1.9.0 is required.
So, because localsend_app depends on path 1.8.3, version solving failed.

尝试执行:flutter pub add path:^1.8.3

解决问题

报错:Error: Type 'AssetEntityImageProvider' not found.

原来是pubspec.yaml文件少修改了一个地方。

dependencies:
  wechat_assets_picker: ^8.9.0-dev.1

报错: cannot open display:

EXTERNAL_USB/tools/localsend/app$ flutter run
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure
you trust this source!
Launching lib/main.dart on Linux in debug mode...
Building Linux application...                                           

(localsend_app:253856): Gtk-WARNING **: 11:39:19.837: cannot open display:
Error waiting for a debug connection: The log reader stopped unexpectedly, or
never started.
Error launching application on Linux.

因为是ssh登录的,所以有这个报错。到xwindows下执行,问题解决。