Flutter SDK安裝和診斷

[TOC]

安裝

本文以Mac系統(tǒng)為例

訪問官網(wǎng)安裝:

https://flutter.dev/docs/get-started/install/macos

下載SDK包flutter_macos_v1.2.1-stable.zip

命令行執(zhí)行下面幾個(gè)步驟:

? cd ~/development //替換成自己的目錄
? unzip ~/Downloads/flutter_macos_v1.2.1-stable.zip
? export PATH="$PATH:`pwd`/flutter/bin"
? flutter precache
? flutter doctor

doctor提示問題

Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.3 18D109, locale
    zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 26.0.1)
    ? Flutter requires Android SDK 28 and the Android BuildTools 28.0.3
      To update using sdkmanager, run:
        /Users/david/Library/Android/sdk/tools/bin/sdkmanager
        "platforms;android-28" "build-tools;28.0.3"
      or visit https://flutter.io/setup/#android-setup for detailed
      instructions.
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 10.2)
    ? 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
[!] Android Studio (version 2.3)
    ? Flutter plugin not installed; this adds Flutter specific functionality.
    ? Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.7.2)
    ? Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[!] Connected device
    ! No devices available

! Doctor found issues in 5 categories.

解決中遇到的問題

1,運(yùn)行precache很慢

Downloading android-arm64-profile/darwin-x64 tools... ? (This is taking an unexpect

解決方案

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

2,更新brew很慢

解決方案

使用中科大的鏡像替換默認(rèn)源

  • 第一步,替換brew.git
? cd "$(brew --repo)"
? git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
  • 第二步:替換homebrew-core.git
? cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
? git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
  • 最后使用下面命令進(jìn)行更新,發(fā)現(xiàn)速度變的很快。替換鏡像完成。
? brew update

3,brew遇到SSL certificate problem

? brew install --HEAD usbmuxd
==> Cloning https://git.sukimashita.com/libusbmuxd.git
Cloning into '/Users/david/Library/Caches/Homebrew/usbmuxd--git'...
fatal: unable to access 'https://git.sukimashita.com/libusbmuxd.git/': SSL certificate problem: certificate has expired
Error: An exception occurred within a child process:
  DownloadError: Failed to download resource "usbmuxd"
Failure while executing; `git clone --branch master https://git.sukimashita.com/libusbmuxd.git /Users/david/Library/Caches/Homebrew/usbmuxd--git` exited with 128. Here's the output:
Cloning into '/Users/david/Library/Caches/Homebrew/usbmuxd--git'...
fatal: unable to access 'https://git.sukimashita.com/libusbmuxd.git/': SSL certificate problem: certificate has expired

解決方案

? git config --global http.sslVerify false

4,android-licenses長(zhǎng)時(shí)間沒有反應(yīng)

? flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel beta, v1.3.8, on Mac OS X 10.14.3 18D109, locale zh-Hans-CN)
? Checking Android licenses is taking an unexpectedly long time...

解決方案

? flutter doctor --android-licenses
Warning: File /Users/david/.android/repositories.cfg could not be loaded.
All SDK package licenses accepted.======] 100% Computing updates...

5,Install the Flutter and Dart plugins

Android Studio 解決方案

To install these:

  • Start Android Studio.
  • Open plugin preferences (Preferences > Plugins on macOS, File > Settings > Plugins on Windows & Linux).
  • Select Browse repositories, select the Flutter plugin and click Install.
  • Click Yes when prompted to install the Dart plugin.
  • Click Restart when prompted.

VSCode 解決方案

  • Start VS Code.
  • Invoke View > Command Palette….
  • Type “install”, and select Extensions: Install Extensions.
  • Type “flutter” in the extensions search field, select Flutter in the list, and click Install. This also installs the required Dart plugin.

VSCode Validate your setup with the Flutter Doctor

  • Invoke View > Command Palette….
  • Type “doctor”, and select the Flutter: Run Flutter Doctor.
  • Review the output in the OUTPUT pane for any issues.

6,Android SDK版本不匹配

? flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel beta, v1.3.8, on Mac OS X 10.14.3 18D109, locale
    zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    ? Flutter requires Android SDK 28 and the Android BuildTools 28.0.3
      To update using sdkmanager, run:
        /Users/david/Library/Android/sdk/tools/bin/sdkmanager
        "platforms;android-28" "build-tools;28.0.3"
      or visit https://flutter.io/setup/#android-setup for detailed
      instructions.
[?] iOS toolchain - develop for iOS devices (Xcode 10.2)
[?] Android Studio (version 3.3)
[?] VS Code (version 1.32.3)
[?] Connected device (1 available)

解決方案

  • 點(diǎn)擊androidStudio菜單的Settings
  • 點(diǎn)擊Appearance&Behavior
  • 點(diǎn)擊System Settings
  • 安裝Android SDK 28

最后所有診斷都通過

? flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel beta, v1.3.8, on Mac OS X 10.14.3 18D109, locale
    zh-Hans-CN)
[?] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[?] iOS toolchain - develop for iOS devices (Xcode 10.2)
[?] Android Studio (version 3.3)
[?] VS Code (version 1.32.3)
[?] Connected device (1 available)

7. 新建flutter項(xiàng)目flutter Resolving dependencies...很慢

打開和新建flutter項(xiàng)目時(shí)發(fā)現(xiàn),flutter Resolving dependencies...很慢。

解決辦法:

打開Flutter SDK:flutter\packages\flutter_tools\gradle\flutter.gradle
改為以下即可解決!

buildscript {
    repositories {
       // google()
       // jcenter()
        maven{ url 'https://maven.aliyun.com/repository/google' }
        maven{ url 'https://maven.aliyun.com/repository/jcenter' }
        maven{url 'http://maven.aliyun.com/nexus/content/groups/public'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容