首先克隆基础flutter项目到本地
git clone -b beta https://github.com/flutter/flutter.git
添加在./.base_profile中添加flutter环境变量:
export PATH_TO_FLUTTER_GIT_DIRECTORY=/Users/用户名/flutter
export PATH={PATH_TO_FLUTTER_GIT_DIRECTORY}/bin
在AndroidStudio中安装flutter的plugin
由于国内网络限制可修改镜像地址解决,如下:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
git clone -b dev https://github.com/flutter/flutter.git
export PATH="PATH"
cd ./flutter
flutter doctor
doctor检测完毕后可能遇到如下:
[✓] Flutter (Channel beta, v1.1.8, on Mac OS X 10.14.2 18C54, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[!] 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
✗ ios-deploy not installed. To install:
brew install ios-deploy
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS platform side's plugin code that
responds to your plugin usage on the Dart side.
Without resolving iOS dependencies with CocoaPods, plugins will not work
on iOS.
For more info, see https://flutter.io/platform-plugins
To install:
brew install cocoapods
pod setup
[✓] Android Studio (version 3.2)
[!] IntelliJ IDEA Ultimate Edition (version 2018.1.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
! Doctor found issues in 4 categories.
第一个感叹号,是需要同意证书问题。输入命令:
flutter doctor --android-licenses
然后一路y,同意就行了。
然后在AndroidStudio新建项目时候会发现fluter项目了。
如果在安装中或者运行中出现:
Waiting for another flutter command to release the startup lock...
解决:则删除flutter/bin/cache/lockfile文件。然后重启AndroidStudio或者terminal
如果遇到下载问题比如:flutter packages get一直loading。有可能被墙了。
解决:
添加环境变量:在./.bash_profile添加镜像
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
然后source ./.bash_profile 立即生效。重新打开terminal,执行flutter doctor命令。这样这个镜像就起作用了。