个人环境搭建遇到问题解决方案总结
VS问题1: bin/sh dart:command not found
VS问题2: 提示Could not find a Flutter SDK
VS问题3: For full Dart language support, please open a folder containing your Dart files instead of individual loose files
AS问题1: AndroidStudio 打开新项目, 顶部提示: 'package get' has not been run
AS问题2: 提示Could not find a Flutter SDK
AS问题3: For full Dart language support, please open a folder containing your Dart files instead of individual loose files
AS问题4: it is taking an unexpectedly long time.
AS问题5: Checking Android licenses is taking an unexpectedly long time...
AS问题6: AndroidStudio安装完flutter,dart插件后,重启,AndroidStudio再次提示没有安装dart,实际上flutter sdk中已经有dart了
AS问题7: Failed to install the following Android SDK packages as some licences have not been accepted
AS问题8: No active package devtools. pub finished with exit code 65
一、VSCode 配置问题:
问题1: bin/sh dart:command not found
错误: VSCode 运行时显示错误: bin/sh dart:command not found
或者写代码时,基本函数不提示, 比如main函数不自动显示代码块
解决:
1.首先确定已经安装Dart和Flutter插件.
2.然后要确定环境是否正确配置, 打开.bash_profile
,参考上边配置
open ~/.bash_profile
3.安装dart环境
$ brew tap dart-lang/dart
$ brew install dart
4.重启VSCode
问题2: 提示Could not find a Flutter SDK
使用VSCode打开flutter项目, 如果提示显示错误信息: Could not find a Flutter SDK. Please ensure flutter is installed and in your PATH (you may need to restart).
**解决: **
这说明我们上面配置flutter命令没有成功,检测一下路径是否有问题,可以cd到本地flutter目录下,使用flutter -h,查看运行结果,如果失败,就检测一下路径。
如果上面路径下提示成功,在其他路径下提示不成功,那么进行下面命令:
vim ~/.zshrc
在打开的文件里最下面增加一行代码,就是配置的路径
export PATH=本地flutter路径/bin:$PATH
保存退出后,再使用source命令重新加载一下:
source ~/.zshrc
到这里,应该可是在任何路径下使用flutter命令了。
问题3: For full Dart language support, please open a folder containing your Dart files instead of individual loose files
原因:
如果直接新建一个 .dart 文件进行编辑不支持,需要新建一个文件夹,再在里面新建 .dart文件就可以了.
解决:
提示翻译: 要获得Dart语言的全面支持,请打开一个包含Dart文件的文件夹.
所以点击打开文件夹按钮, 找到新建dart文件所在文件夹即可.
二、AndroidStudio配置问题
问题1: AndroidStudio 打开新项目, 顶部提示: 'package get' has not been run
错误信息:Flutter: 'package get' has not been run; 'Pub get' has not been run
原因: Dart与node类似。它有一个pubspec.yaml相当于package.json包含你的依赖项和内容的项。需要下载这些依赖项。
解决:
参考stackoverflow
此警告仅在此处提醒您未下载依赖项 =>单击Get Dependencies第一个警告.
- 如果卡在
flutter packages get
, 请看问题2
问题2: flutter packages get 慢或者卡
错误信息: Running "flutter pub get" in xxx
如果默认镜像已经修改为国内镜像,并重新执行命令安装;结果问题还是出现。
1) .zshrc文件没有配置
如果你使用终端是zsh,终端启动时 ~/.bash_profile 将不会被加载,解决办法就是修改 ~/.zshrc ,在其中添加:
source ~/.bash_profile
重启
2) 终端优先执行下面三条指令尝试:
此方法修改临时环境的配置
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
flutter packages get
3) 手动下载插件直接放本地使用
如果网络正常,镜像正常,环境正常,三条指令执行后,还是依旧会出现卡在flutter packages get
的情况。可以考虑手动下载插件直接放本地使用。
这里就直接po出flutter插件默认本地路径:
flutter的SDK目录/.pub-cache/hosted/当前使用的镜像地址文件夹/
参考示例:
/usr/local/flutter1.5.4/.pub-cache/hosted/pub.flutter-io.cn/
- 在
hosted
文件夹下,可以发现几个以flutter镜像域名命名的文件夹
./hosted
.../dart-pub.mirrors.sjtug.sjtu.edu.cn%47/
.../pub.dartlang.org/
.../pub.flutter-io.cn/
可见下载的依赖包都是按不同镜像分目录存放,所以每切一回镜像,都需要重新下载所有项目的依赖插件;因为加载的插件较多,也就导致等待时间非常久,这也是切换了几个国内镜像依旧卡flutter packages get很久的原因。
解决方法:
第一步,按需选择操作步骤:
- 耐心等待下载(若下载的插件数量非常多,等待的耗时会比较长)
- 将其他镜像文件夹下已下载的插件文件,拷贝到当前使用的镜像的目录下,并执行flutter packages get(避免有遗漏的插件)
- 手动到插件的github下载文件,放到当前使用的镜像目录下
第二步,执行flutter run
。
问题3: Waiting for another flutter command to release the startup lock...
- 方法一: 删除flutter SDK 下的/bin/cache/lockfile文件, 重启Android Studio。
- 方法二: 启动mac自带的活动监视器, 搜索dart, 将所有dart进程关闭即可。此方法不需要重启Android Studio, 所以建议方法二。
问题4: it is taking an unexpectedly long time.
Please try steps below:
a. delete all contents under /home/nima/.gradle
b. cd to the android folder for your flutter project and run ./gradlew sync command, it will download the gradle-xxx.zip automatically. It this gradle process succeeds, re-run the flutter run command.
翻译:
- 1> 删除
/home/nima/.gradle
下的所有内容 - 2> cd到flutter项目的android文件夹并运行./gradlew sync 命令,它将自动下载gradle-xxx.zip。如果此gradle过程成功,请重新运行flutter run命令。
- 3> flutter run -v
flutter run -v : it usually download gradle(which is a large file) for the first time you run a flutter program.The above will help you to see the message that its downloading gradle/dist.It wont happen from the next program
问题5: Checking Android licenses is taking an unexpectedly long time...
终端运行
flutter doctor --android-licenses
会检查是否需要更新 Android SDK ,并重启电脑
如下提示则成功:
All SDK package licenses accepted.======] 100% Computing updates...
问题6: AndroidStudio安装完flutter,dart插件后,重启,AndroidStudio再次提示没有安装dart,实际上flutter sdk中已经有dart了
解决:AndroidStudio需要设置flutter的目录,设置方法:
file->setting->languages&Frameworks->flutter
问题7: Failed to install the following Android SDK packages as some licences have not been accepted
解决:
用flutter进行编写时出现了标题的错误,不是配置的原因,而是需要接受SDK的证书,反正不难操作即可解决。
- 1、首先打开控制台,使用如下命令:
cd /Users/你的用户名/Library/Android/sdk
cd tools
cd bin
- 2、最关键的一部就是下面这个语句
sdkmanager.bat --licenses
执行之后,它会提示你去允许认证,然后
命令会提醒你确定y/n(accept lincense),一路y下去便可以了。
参考解决方案
问题8: No active package devtools. pub finished with exit code 65
- Android Studio 点击 Open in DevTools時,报错:
No active package devtools. pub finished with exit code 65
解决:
没有安装DevTools, 终端调用命令安装, 安装后重新启动Android Studio, 并运行项目,再次点击Open in DevTools
flutter packages pub global activate devtools
- 如果没有安装成功, 并且提示以下信息,按照信息提示,在
.bash_profile
文件中添加
export PATH="$PATH":"你的flutterSDK路径/.pub-cache/bin"
Warning: Pub installs executables into /Users/SKFlutter/flutter/.pub-cache/bin, which is not on your path.
You can fix that by adding this to your shell's config file (.bashrc, .bash_profile, etc.):
export PATH="$PATH":"你的flutterSDK路径/.pub-cache/bin"
Activated devtools 0.2.5.
再次执行
flutter packages pub global activate devtools