In order to facilitate the transmission of data between mobile phones and computers, and to consider the convenience of computer transmission in the next step, I discovered the open source software localsend from the Internet. This software was developed based on flutter. It took more than half a day to compile successfully. Let me record the learning process.
1. localsend software
LocalSend is a free, open source, cross-platform LAN file transfer tool that does not require the Internet or external servers. It works out of the box and supports Windows, macOS, Linux, iOS, and Android.
LocalSend is open source on GitHub. You can compile the client yourself and then use it on the intranet. The download address is as follows:
GitHub - localsend/localsend: An open-source cross-platform alternative to AirDrop
2. Introduction to Flutter
Flutter is Google's mobile UI framework. "With just one code base, you can build, test and publish beautiful applications for mobile, web, desktop and embedded platforms." From Xianyu to Taobao, from QQ to WeChat, from First-line Internet companies such as JD.com to Baidu, Meituan to Douyin, and BAT are fully embracing Flutter. 2020 In just one year, Flutter has overtaken React Native to become the preferred cross-platform framework for developers on GitHub and StackOverflow.
Flutter has the following features:
- It has cross-platform development characteristics and supports IOS, Android, and Web terminals.
- Hot reload feature greatly improves development efficiency
- The self-drawn UI engine and the method of compiling into native code make the system's runtime high performance possible.
- Using the Dart language, it currently supports compiling into web code at the same time.
3. Build a flutter development environment
For details, see https://flutter.cn/community/china: Using Flutter in China’s Internet Environment - Flutter Chinese Documentation - Flutter Chinese Developer Website - Flutter
To install and run Flutter on Windows, you must meet the following minimum requirements:
Operating system: Windows 7 SP1 or later
Disk space: 400 MB (excluding IDE/tools disk space).
Tools: Flutter relies on the following command line tools:
Windows PowerShell 5.0 Windows 10 comes pre-installed with this tool;
Git for Windows 2.x ensure that the Windows computer has downloaded and installed the Git tool;
Take Tsinghua Mirror as an example
3.1 Set environment variables
PUB_HOSTED_URL=https://mirrors.tuna.tsinghua.edu.cn/dart-pub
FLUTTER_STORAGE_BASE_URL=https://mirrors.tuna.tsinghua.edu.cn/flutter
3.2 Download SDK
Flutter SDK archive list - Flutter Chinese documentation - Flutter Chinese developer website - Flutter Download the stable version SDK. At first, I downloaded the latest 3.16.3 (later I found out that I had dug a big hole for myself).
Unzip the installation package zip to the path where you want to install Flutter SDK (such as: C:\src\flutter; be careful not to install flutter to a path that requires high permissions, such as C:\Program Files\).
Set the Path environment variable:
3.3 Obtain dependencies
Use the CMD window to enter the downloaded localsend source program path and execute:
E:\Software\localsend-1.13.1\localsend-1.13.1\app>flutter pub get
After configuring the environment variables, manually or automatically executing flutter pub get, the dependency package cannot be downloaded normally. After a long time, the following error will appear: Got TLS error trying to find package xxx
solution:
Use 360 browser to open Index of /dart-pub/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror
Right click properties:
Export the flutter_pub.der certificate file, and then use openssl to convert it into a pem file
E:\flutter>openssl x509 -inform der -in flutter_pub.der -out flutter_pub.pem
Note: https://www.sslshopper.com/certificate-decoder.html can check whether the pem file is correct. The results are as follows:
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
Then configure the environment variables
DART_VM_OPTIONS=--root-certs-file=E:\flutter\flutter_pub.pem
Execute the command again and download the dependencies successfully.
3.4 Install VS2022
Since you want to compile the flutter program under Windows, you need to open the developer mode of the system and execute the command start ms-settings:developers
For Windows desktop development, in addition to the Flutter SDK, you also need the following:
Visual Studio 2022 or Visual Studio 2022 Build Tools When you choose to install Visual Studio or only the build tools, you need to select "Desktop Development with C++", including all its default components, to install the necessary C++ toolchain and Windows SDK header file.
Download Visual Studio, download address: https://visualstudio.microsoft.com/zh-hans/downloads/
After running the installer, select Use C++ for desktop development workloads, including all of its default components
Basically, if you want to develop Flutter apps for Windows, you need to install Visual Studio 2022. When installing Visual Studio 2022, you need to download: Desktop development with C++
3.5 flutter doctor check
Run flutter doctor to check
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.
At this point, the construction of the flutter environment is completed.
4. Compile localsend software
Execute in the path E:\Software\localsend-1.13.1\localsend-1.13.1\app:
flutter build windows
At first, because I downloaded the 3.16.3 version of flutter, the compilation error was reported:
/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]
I wasted a lot of time and re-downloaded the 3.13.9 version of flutter to solve the problem.
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).