flutter环境基本搭建
开发IDE选择android studio.Mac环境
1.下载flutter到本地
git clone -b beta https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH
2.为了让flutter可以处处使用,配置环境变量 .bash_profile
open -e .bash_profile //打开环境变量配置文件,下面第一行配置环境变量,二三行是使用国内镜像
export PATH=$PATH:/Users/laomao/files/flutter/bin
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
3.flutter 检测开发环境配置
flutter doctor //执行这个命令查看开发环境缺少哪些
以下是本机执行结果:
laomaodeMacBook-Pro:~ laomao$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.1.5, on Mac OS X 10.13.1 17B1003, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.0)
[!] iOS toolchain - develop for iOS devices (Xcode 9.2)
✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
brew install --HEAD libimobiledevice
brew install ideviceinstaller
✗ 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.0)
[!] VS Code (version 1.19.3)
[✓] Connected devices (1 available)
! Doctor found issues in 2 categories.
4.安装android studio插件Flutter和dart,搜索安装Flutter默认会提示安装dart
如果安装不到,我尝试N次安装失败,那么直接去插件网站下载安装即可.
https://plugins.jetbrains.com/androidstudio 如果打不开,请科学上网.
下载时候注意对应as的版本号选择正确版本,最新的不一定能用.
5,新建一个flutter项目
运行IOS模拟器很顺利,运行Android你可能遇到各种奇葩的问题.
比方:
Q:Finished with error: Exit code 1 from: /Users/laomao/files/as/flutter_app/android/gradlew -v:
A:下载gradle-4.6解压
修改android下gradlew文件
第一处:
#CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
CLASSPATH=/Applications/Android\ Studio.app/Contents/gradle/gradle-4.6/lib/gradle-launcher-4.6.jar
第二处:
#exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.launcher.GradleMain "$@"
Q:提示同意协议,又找不到sdkmanager 命令
A:flutter config --android-sdk C:\Users\user\AppData\Local\Android\sdk\