Win10下flutter编译localsend笔记

为了方便手机和电脑之间的传输数据,同时考虑下一步局域网内电脑传输方便性,从网上发现了开源软件localsend,该软件是基于flutter开发的,历时大半天才编译成功,记录一下学习过程。

1、localsend软件

LocalSend 是一款免费、开源、跨平台的局域网文件互传工具,无需互联网,无需外部服务器。即开即用,支持 Windows、macOS、Linux,以及 iOS、Android。

LocalSend 在 GitHub 开源,你完全可以自己编译客户端,然后在内网使用。下载地址如下:

GitHub - localsend/localsend: An open-source cross-platform alternative to AirDrop

2、flutter简介

flutter是谷歌的移动UI框架,“只要一套代码库,即可构建、测试和发布适用于移动、Web、桌面和嵌入式平台的精美应用”,从闲鱼到淘宝,从QQ到微信,从京东到百度,从美团到抖音,BAT等一线互联网大厂在全面拥抱Flutter。2020 短短一年里,Flutter在GitHub 和 StackOverflow已经赶超React Native成为开发者首选跨平台框架。

flutter具有以下特性:

  1. 具有跨平台开发特性,支持IOS、Android、Web三端。
  2. 热重载特性大大提高了开发效率
  3. 自绘UI引擎和编译成原生代码的方式,使得系统的运行时的高性能成为了可能
  4. 使用Dart语言,目前已经支持同时编译成Web端代码

3、搭建flutter开发环境

详见https://flutter.cn/community/china:在中国网络环境下使用 Flutter - Flutter 中文文档 - Flutter 中文开发者网站 - Flutter

在Windows上要安装并运行Flutter要满足以下最低要求: 

操作系统: Windows 7 SP1或更新版本

磁盘空间: 400 MB (不包括IDE/tools的磁盘空间).

工具: Flutter 依赖下面这些命令行工具:

Windows PowerShell 5.0 Windows 10已经预装了这个工具;

Git for Windows 2.x确保Windows电脑下载并安装了Git工具;

以清华镜像为例

3.1设置环境变量

PUB_HOSTED_URL=https://mirrors.tuna.tsinghua.edu.cn/dart-pub

FLUTTER_STORAGE_BASE_URL=https://mirrors.tuna.tsinghua.edu.cn/flutter

3.2下载SDK

Flutter SDK 归档列表 - Flutter 中文文档 - Flutter 中文开发者网站 - Flutter 下载稳定版本SDK,最开始我下载了最新的3.16.3(后来发现给自己挖了一个大坑)。

将安装包zip解压到你想安装Flutter SDK的路径(如:C:\src\flutter;注意,不要将flutter安装到需要一些高权限的路径如C:\Program Files\)。

设置Path环境变量:

3.3获取依赖

     利用CMD窗口进入下载好的localsend源程序路径下执行:

E:\Software\localsend-1.13.1\localsend-1.13.1\app>flutter pub get

当配置好环境变量后,手动或自动执行 flutter pub get 后会使用无法正常下载依赖包,时间长了会出现下面的错误Got TLS error trying to find package xxx

解决方案:

利用360浏览器打开Index of /dart-pub/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

右键属性:

导出flutter_pub.der证书文件,然后利用openssl转化成pem文件

E:\flutter>openssl x509 -inform der -in flutter_pub.der -out flutter_pub.pem

说明:https://www.sslshopper.com/certificate-decoder.html可以查看pem文件是否正确,结果如下:

Certificate Information:

Common Name: tuna.tsinghua.edu.cn

Subject Alternative Names: *.tuna.tsinghua.edu.cn, tuna.tsinghua.edu.cn

Organization:

Organization Unit:

Locality:

State:

Country:

Valid From: December 7, 2023

Valid To: March 6, 2024

Issuer: R3, Let's Encrypt

Key Size: 2048 bit

Serial Number: 0360c873c42e84d581f57896df6c2921c5c1

接着配置环境变量

DART_VM_OPTIONS=--root-certs-file=E:\flutter\flutter_pub.pem

再次执行命令,成功下载依赖。

3.4安装VS2022

     由于要在windows下编译flutter程序,需要打开系统的开发者模式,执行命令start ms-settings:developers

对于 Windows 桌面开发而言,除了 Flutter SDK 以外你还需要以下内容:

Visual Studio 2022 或 Visual Studio 2022 生成工具 在选择安装 Visual Studio 时或只安装生成工具的时候,你需要选择「使用 C++ 的桌面开发」,包括其所有默认组件,以安装必要的 C++ 工具链和 Windows SDK 的头文件。

下载Visual Studio,下载地址:https://visualstudio.microsoft.com/zh-hans/downloads/

运行安装程序后,选择 使用 C++ 进行桌面开发工作负载,包括其所有默认组件

https://img-blog.csdnimg.cn/cc43d7a197c3414ebf2a62e109361058.png

基本上是说,如果您想为 Windows 开发 Flutter 应用程序,则需要安装Visual Studio 2022,在安装 Visual Studio 2022 时,您需要下载:Desktop development with C++

3.5 flutter doctor检查

运行flutter doctor检查

E:\flutter>flutter doctor

Flutter assets will be downloaded from https://mirrors.tuna.tsinghua.edu.cn/flutter. Make sure you trust this source!

Doctor summary (to see all details, run flutter doctor -v):

[√] Flutter (Channel stable, 3.13.9, on Microsoft Windows [版本 10.0.19045.3693], locale zh-CN)

[√] Windows Version (Installed version of Windows is version 10 or higher)

[X] Android toolchain - develop for Android devices

    X 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/windows#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.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)

    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.3)

[!] Android Studio (not installed)

[√] Connected device (2 available)

[√] Network resources

! Doctor found issues in 3 categories.

此时就完成了flutter环境的构建。

4、localsend软件编译

在E:\Software\localsend-1.13.1\localsend-1.13.1\app路径下执行:

flutter build windows

最开始由于我下载的3.16.3版本的flutter,编译报错:

/C:/Users/Administrator/AppData/Local/Pub/Cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub%2547/photo_manager-2.8.1/lib/src/internal/image_provider.dart(71,5): error G5FE39F1E: Type 'DecoderCallback' not found. [E:\Software\localsend-1.13.1\localsend-1.13.1\app\build\windows\x64\flutter\flutter_assemble.vcxproj]

/C:/Users/Administrator/AppData/Local/Pub/Cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub%2547/photo_manager-2.8.1/lib/src/internal/image_provider.dart(96,5): error G5FE39F1E: Type 'DecoderCallback' not found. [E:\Software\localsend-1.13.1\localsend-1.13.1\app\build\windows\x64\flutter\flutter_assemble.vcxproj]

/C:/Users/Administrator/AppData/Local/Pub/Cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub%2547/photo_manager-2.8.1/lib/src/internal/image_provider.dart(71,5): error G93EAFBA7: 'DecoderCallback' isn't a type. [E:\Software\localsend-1.13.1\localsend-1.13.1\app\build\windows\x64\flutter\flutter_assemble.vcxproj]

/C:/Users/Administrator/AppData/Local/Pub/Cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub%2547/photo_manager-2.8.1/lib/src/internal/image_provider.dart(96,5): error G93EAFBA7: 'DecoderCallback' isn't a type. [E:\Software\localsend-1.13.1\localsend-1.13.1\app\build\windows\x64\flutter\flutter_assemble.vcxproj]

e:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): error MSB8066:   E:\Software\localsend-1.13.1\localsend-1.13.1\app\build\windows\x64\CMakeFiles\3e2763436f533117eea22937f39400f3\flutter_windows.dll.rule;E:\Software\localsend-1.13.1\localsend-1.13.1\app\build\windows\x64\CMakeFiles\2a8a145387b0dca97778dabe97f93418\flutter_assemble.rule; [E:\Software\localsend-1.13.1\localsend-1.13.1\app\build\windows\x64\flutter\flutter_assemble.vcxproj]

耽误了很多时间,重新下载3.13.9版本的flutter解决问题。

E:\Software\localsend-1.13.1\localsend-1.13.1\app>flutter build windows

Flutter assets will be downloaded from https://mirrors.tuna.tsinghua.edu.cn/flutter. Make sure you trust this source!

Building Windows application...                                   126.7s

√  Built build\windows\runner\Release\localsend_app.exe (0.2MB).

猜你喜欢

转载自blog.csdn.net/qq_39621571/article/details/134967879
今日推荐