安裝
git clone -b dev https://github.com/flutter/flutter.git
cd flutter
./bin/flutter config --no-analytics
禁用通過 Google Analytics 發(fā)送數據(以免國內網絡連接失敗問題)./bin/flutter doctor
創(chuàng)建項目
最簡單的命令只要 flutter create my_flutter_app
即可颠毙。注意 flutter 建議使用使用這樣命名方式胎挎。
關于 創(chuàng)建項目的更多選項參考: 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
這個時候可以考慮使用國內的鏡象户誓。下面是我們的環(huán)境變量配置:
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.