发表日期:2018-11 文章编辑:小灯 浏览次数:2620
bash, mkdir, rm, git, curl, unzip Documents 目录下unzip ~/Documents/下载下来的包-beta.zip flutter 命令解压缩后,不要急着进入 flutter 文件夹,还停留在 Documents 文件目录下(或者执行 cd ~/Documents 切到这个目录),然后执行下面的命令:
$ export PATH=$PATH:`pwd`/flutter/bin 有了这一步,可以避免这个问题: command not found: flutter
执行下面命令来检测本机环境依赖
$ flutter doctor 输出如下:
[✓] Flutter (Channel beta, v0.11.3, on Mac OS X 10.14 18A391, locale zh-Hans-CN) [✗] Android toolchain - develop for Android devices ✗ Unable to locate Android SDK. Install Android Studio from: https://developer.android.com/studio/index.html On first launch it will assist you in installing the Android SDK components. (or visit https://flutter.io/setup/#android-setup for detailed instructions). If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location. You may also want to add it to your PATH environment variable.[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1) ✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run: brew update brew install --HEAD usbmuxd brew link usbmuxd brew install --HEAD libimobiledevice brew install ideviceinstaller ✗ ios-deploy not installed. To install with Brew: brew install ios-deploy [!] Android Studio (not installed) [✓] VS Code (version 1.29.0) [✓] Connected device (2 available) 显示叉号 ✗ 的,表示相应的工具没有安装。其中比较重要的两大开发工具是:Xcode 和 Android Statudio。
如果这两个没有安装,需要根据你的开发者身份,安装对应的开发工具
Xcode,最好是最新版本的Xcode,同意它的 license 等(适用于新装Xcode)Xcode command-line 指定要使用的 Xcode 版本:$ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer iPhone 5s 或之后版本的模拟器,然后执行:$ open -a Simulator $ brew update $ brew install --HEAD usbmuxd $ brew link usbmuxd $ brew install --HEAD libimobiledevice $ brew install ideviceinstaller ios-deploy cocoapods $ pod setup 进入某个 flutter 项目目录
$ cd ~/Documents/flutter/examples/hello_world 执行命令,安装 hello_world 到模拟器:
$ flutter run 运行一会后,模拟器已经安装了hello_world,但并没有launch。也许会报错:
ProcessException: Process "/usr/bin/xcrun" exited abnormally: "io.flutter.examples.hello-world": -1An error was encountered processing the command (domain=FBSOpenApplicationServiceErrorDomain, code=1): The request to open ""io.flutter.examples.hello-world"" failed. The request was denied by service delegate (SBMainWorkspace) for reason: NotFound ("Application ""io.flutter.examples.hello-world"" is unknown to FrontBoard"). Underlying error (domain=FBSOpenApplicationErrorDomain, code=4): The operation couldn’t be completed. Application ""io.flutter.examples.hello-world"" is unknown to FrontBoard. Application ""io.flutter.examples.hello-world"" is unknown to FrontBoard. Command: /usr/bin/xcrun simctl launch 4B7B9269-47FA-47B6-8096-17AB675A3E4F "io.flutter.examples.hello-world" --enable-dart-profiling --enable-checked-mode --observatory-port=0 Error launching application on iPhone 5s. 这里暴露出了 flutter 的另一个问题:
根据 $(PRODUCT_BUNDLE_IDENTIFIER) 不能成功的launch 模拟器
解决方法是:
Xcode打开 hello-world 项目info.plist Bundle identifier 的值为 io.flutter.examples.hello-world 再次执行 flutter run. 模拟器成功 launch.
Android Studio,执行 “Android Studio Setup Wizard” Developer options 和 USB debugging. 这个文档有详细说明 Android documentation flutter devices flutter run 启用 VM acceleration .
Launch Android Studio ->Tools -> Android -> AVD Manager 并选择 Create Virtual Device.
选择一个设备并选择 Next
为你要模拟的 Android 版本选择一个或多个系统镜像,然后选择 Next. 建议使用 x86 或 x86_64 镜像 .
在 Emulated Performance下, 选择 Hardware - GLES 2.0 启用 硬件加速.
验证AVD配置是否正确,选择 Finish。上述步骤的详细信息,请参阅 Managing AVDs.
在 Android Virtual Device Manager中, 点击 Run 启动模拟器
运行 flutter run . 可以看到连接的设备名称是 Android SDK built for <x86or其他型号>
至此,Flutter 的环境部署就结束了。