flutter大家都知道是google推出的跨平台UI平台,主要用于android/ios的界面开发,其也兼容windows linux mac等平台。
本篇记录搭建windows桌面平台遇到的问题和解决方案。该项目地址为:https://github.com/google/flutter-desktop-embedding
多搞事情,总是会有所收获的,吐槽一下,国内访问谷歌代码服务器会失败的问题实在让人蛋疼。
首先下载需要的项目flutter和flutter-desktop-embedding。
即打开cmd命令行程序运行下面命令(要准备好windows版本的git
D:
mkdir flutter
cd flutter
git clone https://github.com/google/flutter-desktop-embedding.git
git clone https://github.com/flutter/flutter.git
创建工程目录结构为:
your_path\flutter
\Flutter-desktop-embedding
为何要建立这种结构目录?可以在工程的README.md里面看到介绍
The tooling and build infrastructure for this project requires that you have
a Flutter tree in the same parent directory as the clone of this project:
```
<parent dir>
├─ flutter (from https://github.com/flutter/flutter)
└─ flutter-desktop-embedding (from https://github.com/google/flutter-desktop-embedding)
```
其次编译工程需要用到ninja和gn工具,这两个是google自己打造的工程管理工具,跟cmake的功能是类似的。
On Linux and Windows you will also need GN and ninja:
* [ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)
* [gn](https://gn.googlesource.com/gn/)
ninja工具下载很顺利,可以得到想要的exe可执行文件,但gn就呵呵了,我所在的国内环境访问不了谷歌的服务器https://gn.googlesource.com/gn/。

需要找对应的镜像服务器代码,还好github上面也有,给个链接:
gn源码的获取和编译方式一定要这么使用(当然本地没有python,google很喜欢自己搞一套,用cmake不就好了!我本地的python是2.7版本):
git clone https://gn.googlesource.com/gn
cd gn
python build/gen.py
ninja -C out
我就犯了个错误,直接下载zip解压然后python build/gen.py会提示not a git repository(or any of the parent directories):.git错误的。

或者提示No name found,cannot describe anything.

编译gn过程还碰到“stddef.h”:No such file or directory、“stdint.h”:No such file or directory等头文件无法包含的问题,如下

这是因为我的cmd没有编译器的环境问题,采用vs自带的安装环境命令工具就可以了,具体在开始菜单的vs tool里面可以找到。

然后继续运行ninja -C out,又提示错误了,这次是语法错误,提示“constexpr” 函数的语句或子表达式非法。

我在编译这个工程时本地vs最高版本是vs2015,这么看来是要下载个vs2017。的确是这个问题,下载个vs2017编译就没问题了(如上截图,已经是2017的版本^_^)。
gn编译成功后对应目录下会有gn.exe文件,如下图:

到这里gn和ninja工具已经准备好了。
接下用vs2017打开flutter-desktop-embedding里面的example\windows_fde\Example Embedder.sln并编译。
这会儿提示如下:
1>------ 已启动生成: 项目: GLFW Example, 配置: Debug x64 ------
1>Run the embedder library's GN build
1>Checking Dart SDK version...
1>无法将“Unblock-File”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称
1>的拼写,如果包括路径,请确保路径正确,然后重试。
1>所在位置 行:1 字符: 13
1>+ Unblock-File <<<< -Path 'D:\flutter\flutter/bin/internal/update_dart_sdk.ps1
1>'; & 'D:\flutter\flutter/bin/internal/update_dart_sdk.ps1'
1> + CategoryInfo : ObjectNotFound: (Unblock-File:String) [], Comman
1> dNotFoundException
1> + FullyQualifiedErrorId : CommandNotFoundException
1>
1>Flutter requires PowerShell 5.0 or newer.
1>See https://flutter.io/docs/get-started/install/windows for more.
1>Building flutter tool...
1>Running pub upgrade...
1>系统找不到指定的路径。
1>EXEC : error (1): Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
1>Running pub upgrade...
1>系统找不到指定的路径。
关于Flutter requires PowerShell 5.0 or newer.问题,那就去下载一个吧,PowerShell安装包包含在wmf安装包里面了。
地址如下:https://docs.microsoft.com/zh-cn/powershell/wmf/5.1/install-configure
然后EXEC : error (1): Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
这个就麻烦了,具体又是连不上国外服务器https://storage.googleapis.com的问题,需要用镜像服务器代替。可以参考下面这两个地址,要设置环境变量,然后重新git clone flutter才行。
https://flutter.dev/community/china
https://www.cnblogs.com/leechenxiang/p/9878442.html
镜像地址和环境变量名称拷贝出来好了:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
git clone -b dev https://github.com/flutter/flutter.git
接着运行提示找不到json第三方库源文件,不会自动去下载吗!?自己去github下载一个,安装错误提示的路径放进去。
接续运行,提示vsvars64.bat执行失败的问题(忘记截图了)。
有两种方法:
1)cmd里面设置vsvars64.bat所在路径的环境变量如:
set path=D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build;%path%
然后直接在命令行执行Ninja -C out编译工程(不要vs ide了)。
2)在系统环境变量里面添加D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build路径,要让编译指令能找到vsvars64.bat的路径。这时重启vs2017继续编译就没问题了。
最后展示一下运行结果,哈哈哈:

2195

被折叠的 条评论
为什么被折叠?



