美文网首页FlutterFlutter学习教程
Flutter 初体验之安装与创建项目

Flutter 初体验之安装与创建项目

作者: 一半晴天 | 来源:发表于2018-02-28 10:39 被阅读901次

安装

  1. git clone -b dev https://github.com/flutter/flutter.git

  2. cd flutter

  3. ./bin/flutter config --no-analytics 禁用通过 Google Analytics 发送数据(以免国内网络连接失败问题)

  4. ./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.

相关文章

网友评论

  • lljzy:Error output from Xcode build:

    ** 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.
    lljzy:这个是什么问题,android是可以的,ios不行
  • KingLanding94:请问环境变量的配置是配置电脑系统的环境变量吗?还是工程的?
    一半晴天:其实环境变量是没有所谓工程的环境变量。
    一般可以说是分为临时的和非临时的。
    像上面的介绍的应该是配置成非临时的。 也就是你所说的电脑系统的环境变量。
    但是说明的是,我上面的示例是针对 Unix类系统的。
  • 5c897ba7f32a:一直停在这里咋办 Initializing gradle...
    一半晴天:这里是 gradle 的问题了。因为我之前有 Android 开发环境, gradle 环境是已经配置好了。
    你可能需要先搜索配置一下 Gradle 环境。
    Gradle 素来在国内是比较慢的。
  • Ven_X:用flutter create app 创建的项目在哪个目录呢?
    Ven_X:已经找到了,谢谢!
    一半晴天:创建目录是你自己指定的。如果没有指定就是当前目录,按你上面的命令。就是当前目录下的名为 `app` 的目录。

本文标题:Flutter 初体验之安装与创建项目

本文链接:https://www.haomeiwen.com/subject/amkbxftx.html