安装
-
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.
网友评论
↳
** BUILD FAILED **
Xcode's output:
↳
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
While building module 'Flutter' imported from /Users/mory/AndroidStudioProjects/my_flutter_app/ios/Runner/AppDelegate.h:1:
In file included from <module-includes>:1:
In file included from /Users/mory/AndroidStudioProjects/my_flutter_app/ios/Flutter/Flutter.framework/Headers/Flutter.h:37:
In file included from /Users/mory/AndroidStudioProjects/my_flutter_app/ios/Flutter/Flutter.framework/Headers/FlutterAppDelegate.h:11:
/Users/mory/AndroidStudioProjects/my_flutter_app/ios/Flutter/Flutter.framework/Headers/FlutterPlugin.h:140:58: warning: this block declaration is not a prototype [-Wstrict-prototypes]
completionHandler:(nonnull void (^)())completionHandler;
^
void
1 warning generated.
1 warning generated.
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
ld: framework not found Flutter
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Could not build the application for the simulator.
Error launching application on iPhone X.
一般可以说是分为临时的和非临时的。
像上面的介绍的应该是配置成非临时的。 也就是你所说的电脑系统的环境变量。
但是说明的是,我上面的示例是针对 Unix类系统的。
你可能需要先搜索配置一下 Gradle 环境。
Gradle 素来在国内是比较慢的。