發表日期:2018-11 文章編輯:小燈 瀏覽次數:2480
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 的環境部署就結束了。