美文网首页Flutter
Flutter-Mac安装

Flutter-Mac安装

作者: 灬朴一生 | 来源:发表于2019-07-28 03:37 被阅读0次

    Flutter是什么

    Flutter是谷歌的移动UI框架,可以快速在iOS和Android上构建高质量的原生用户界面。 Flutter可以与现有的代码一起工作。在全世界,Flutter正在被越来越多的开发者和组织使用,并且Flutter是完全免费、开源的。

    Flutter中文网


    安装

    • 使用git将Flutter项目克隆到本地,
      然后将Flutter添加到本地环境变量(终端)
    cd 到准备好的文件夹
    git clone -b dev https://github.com/flutter/flutter.git
    

    • 配置

    打开环境变量文件:

    open ~/.bash_profile
    
    WX20190726-110210@2x.png

    保存后,再次执行这个文件:

    source ~/.bash_profile
    

    我们运行一下:

    flutter doctor
    

    第一次运行一个flutter命令(如flutter doctor)时,它会下载它自己的依赖项并自行编译。以后再运行就会快得多


    • 错误
    [✗] 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.
    

    需要安装android studio并且设置好$ANDROID_HOME这个环境变量

    android studio下载

    安装好后,打开bash_profile

    open -e .bash_profile
    

    bash_profile里加上

    export ANDROID_HOME="/Users/用户名/Library/Android/sdk" //android sdk目录,替换为你自己的
    export PATH=${PATH}:${ANDROID_HOME}/tools
    export PATH=${PATH}:${ANDROID_HOME}/platform-tools
    

    更新配置

    source .bash_profile
    

    • 错误
    [✗] 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.dev/setup/#android-setup for detailed
          instructions).
          If the 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.
    

    根据提示运行:

    flutter doctor --android-licenses
    

    然后根据提示一直y,y到结束为止。


    • 错误

    去App Store安装了xcode后,运行

    [✗] iOS tools - develop for iOS devices
        ✗ 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:
            brew install ios-deploy
    

    根据错误提示运行,例如:

    brew update
    ...
    

    如果重复提示 iOS toolchain - develop for iOS devices,进入/usr/local/Cellar目录删除libimobiledeviceusbmuxdideviceinstaller库,重启电脑即可


    • 错误
    [!] Android Studio (version 3.4)
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
    

    打开Android Studio软件 -> preferences

    WX20190728-012519@2x.png

    然后 我们就可以建立flutter的工程了


    • 警告
    [!] Connected device
        ! No devices available
    

    连接手机即可


    • 最终
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel dev, v1.8.2, on Mac OS X 10.13.6 17G5019, locale
        zh-Hans-CN)
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
    [!] Xcode - develop for iOS and macOS (Xcode 10.1)
        ! CocoaPods out of date (1.6.0 is recommended).
            CocoaPods is used to retrieve the iOS and macOS platform side's plugin
            code that responds to your plugin usage on the Dart side.
            Without CocoaPods, plugins will not work on iOS or macOS.
            For more info, see https://flutter.dev/platform-plugins
          To upgrade:
            brew upgrade cocoapods
            pod setup
    [✓] iOS tools - develop for iOS devices
    [✓] Android Studio (version 3.4)
    [✓] Connected device (1 available)
    

    CocoPods 警告我们也可以使用了

    强迫症的解决方案

    找出目前版本的pod路径
    which pod
    
    移除现有pod
    rm -rf /usr/local/bin/pod
    
    重新下载pod
    sudo gem install cocoapods
    

    • 创建项目

    cd 到创建目录

    //在当前路路径创建⼀一个新的名叫flutter_demo的新项⽬目 
    flutter create your_flutter_demo
    
    //创建⼀一个可包含dart源码的flutter库
    flutter create --template=package your_flutter_demo
    
    //创建⼀一个域名为com.guahao的java语⾔言的flutter项⽬目(⽀支持object-C、swift、java、kotlin)
    flutter create --org="com.guahao" -a java your_flutter_demo
    
    在VS Code 面板中,按下快捷键 Ctrl + Shift + P 打开命令面板
    
    在命令面板中输入 flutter
    
    选择 flutter:New Project 选项创建新项目。
    
    • IDE

    这里我使用的Visual Studio Code进行开发

    设置中文
    macOS 快捷键:command + shift + p
    搜索:configure language

    WX20190728-021740@2x.png

    下载插件 shift + command + x

    搜索dart code 安装

    搜索flutter 安装

    写第一个flutter应用

    相关文章

      网友评论

        本文标题:Flutter-Mac安装

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