安装
git clone -b dev https://github.com/flutter/flutter.git
cd flutter
./bin/flutter config --no-analytics
禁用通过 Google Analytics 发送数据(以免国内网络连接失败问题)./bin/flutter doctor
创建项目
最简单的命令只要 flutter create my_flutter_app
即可。注意 flutter 建议使用使用这样命名方式。
关于 创建项目的更多选项参考: flutter help create
如果出现类似下面的错误,多试几次。
➜ ~flutter create -t app --org=banxi1988.com -i swift -a kotlin try_flutter_app
Downloading package sky_engine...(cached)
...
Downloading android-arm64-release tools...
Oops; flutter has exited unexpectedly.
Sending crash report to Google.
Failed to send crash report due to a network error: SocketException: Connection failed (OS Error: No route to host, errno = 65), address = clients2.google.com, port = 443
Crash report written to /Users/banxi/flutter_01.log;
please let us know at https://github.com/flutter/flutter/issues.
后面可能会遇到:
Running "flutter packages get" in try_flutter_app...
Connection failed (OS Error: No route to host, errno = 65), address = storage.googleapis.com, port = 443
这个时候可以考虑使用国内的镜象。下面是我们的环境变量配置:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
设置好镜象之后可以运行其他命令如 flutter run
或者 flutter packages get
来下载依赖。
下面是一次成功的运行过程输出:
➜ try_flutter_app flutter run -d 68U5T17B28005137
Launching lib/main.dart on RNE AL00 in debug mode...
Initializing gradle... 1.0s
Resolving dependencies... 1.0s
Running 'gradlew assembleDebug'... 1.7s
Built build/app/outputs/apk/debug/app-debug.apk (25.8MB).
I/FlutterActivityDelegate(23577): onResume setting current activity to this
Syncing files to device RNE AL00...
I/FlutterActivityDelegate(23577): onResume setting current activity to this
🔥 To hot reload your app on the fly, press "r". To restart the app entirely, press "R".
An Observatory debugger and profiler on RNE AL00 is available at: http://127.0.0.1:8101/
For a more detailed help message, press "h". To quit, press "q".
I/hwaps (23577): JNI_OnLoad
Initializing hot reload...
Reloaded 466 of 482 libraries in 4,422ms.