美文网首页
flutter 环境的搭建 (mac 环境)

flutter 环境的搭建 (mac 环境)

作者: 蝼蚁撼树 | 来源:发表于2019-02-21 17:29 被阅读0次

    主要参考flutter中文官方,结合自己操作过程的问题整理的这篇文章

    使用镜像

    由于在国内访问Flutter有时可能会受到限制,Flutter官方为中国开发者搭建了临时镜像,大家可以将如下环境变量加入到用户环境变量中:

    export PUB_HOSTED_URL=https://pub.flutter-io.cn
    export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
    

    注意: 此镜像为临时镜像,并不能保证一直可用,读者可以参考详情请参考 Using Flutter in China 以获得有关镜像服务器的最新动态。

    获取Flutter SDK

    1.去Flutter官网下载官网地址 或者 去github上下载git地址
    2.解压安装包到你想安装的目录,如:

    cd ~/Users/#自己的账户名#
    unzip ~/Downloads/flutter_macos_v0.5.1-beta.zip  #下载的zip文件#
    

    3.添加flutter相关工具到path中:(在步骤2当前路径下)

    export PATH=`pwd`/flutter/bin:$PATH
    

    运行 flutter doctor

    [✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.6 17G4015, locale
        zh-Hans-CN)
    [!] Android toolchain - develop for Android devices
        ✗ No valid Android SDK platforms found in
          /Users/chengguangfa/Library/Android/sdk/platforms. Directory was empty.
    [!] iOS toolchain - develop for iOS devices (Xcode 10.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
    [✓] Android Studio (version 3.3)
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
    [!] Connected device
        ! No devices available
    

    [✓]表示没有问题, 表示有错误需要按照提示去安装

    1.先修复iOS toolchain 问题

    [!] iOS toolchain - develop for iOS devices (Xcode 10.1)
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with
    Brew, run:
    brew update #step1
    brew install --HEAD usbmuxd #step2
    brew link usbmuxd #step3
    brew install --HEAD libimobiledevice #step4
    brew install ideviceinstaller #step5

    前三步的时候没啥问题, 到第四步的时候死活装不上提示:
    Cloning into '/Users/chengguangfa/Library/Caches/Homebrew/libimobiledevice--git'... fatal: unable to access 'https://git.libimobiledevice.org/libimobiledevice.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to git.libimobiledevice.org:443
    的错误SSL_ERROR_SYSCALL,
    查了下资料才知道是被墙了. 挂着梯子,再次brew install --HEAD libimobiledevice, 成功!!!

    bogon:flutter_Place chengguangfa$  brew install --HEAD libimobiledevice
    ==> Cloning https://git.libimobiledevice.org/libimobiledevice.git
    Cloning into '/Users/chengguangfa/Library/Caches/Homebrew/libimobiledevice--git'...
    ==> Checking out branch master
    Already on 'master'
    Your branch is up to date with 'origin/master'.
    ==> ./autogen.sh
    ==> ./configure --disable-silent-rules --prefix=/usr/local/Cellar/libimobiledevi
    ==> make install
    🍺  /usr/local/Cellar/libimobiledevice/HEAD-0584aa9_3: 67 files, 1MB, built in 8 minutes 24 seconds
    Removing: /Users/chengguangfa/Library/Caches/Homebrew/libimobiledevice--1.2.0_3.high_sierra.bottle.tar.gz... (280.8KB)
    

    修复完iOS toolchain的问题后, 继续flutter doctor

    bogon:flutter_Place chengguangfa$ flutter doctor
    [✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.6 17G4015, 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 10.1)
    [!] Android Studio (not installed)
    [!] Connected device
        ! No devices available
    

    其他的主要是Andriod Studio 没安装的问题,

    安装Android Studio

    要为Android开发Flutter应用,您可以使用Mac,Windows或Linux(64位)机器.

    Flutter需要安装和配置Android Studio:

    1. 下载并安装 Android Studio.

    2. 启动Android Studio,然后执行“Android Studio安装向导”。这将安装最新的Android SDK,Android SDK平台工具和Android SDK构建工具,这是Flutter为Android开发时所必需的

    3. 打开android studio, 打开plugin


      image.png
    4. 安装Flutter,安装Flutter会提示你安装dart, 点击安装


      image.png
    5. 点击install,顺利的话安装完毕之后重启android studio

    开始你的Flutter之旅吧....

    相关文章

      网友评论

          本文标题:flutter 环境的搭建 (mac 环境)

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