android studio 3.0以上
环境搭建
1.镜像:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
android sdk 路径放入系统变量中 android中
2.下载git,flutter sdk
3.下载AS3.0以上
4:要在终端运行 flutter 命令, 你需要添加以下环境变量到系统PATH:
- 转到 “控制面板>用户帐户>用户帐户>更改我的环境变量”
- 在“用户变量”下检查是否有名为“Path”的条目:
- 如果该条目存在, 追加 flutter\bin的全路径,使用 ; 作为分隔符.
- 如果条目不存在, 创建一个新用户变量 Path ,然后将 flutter\bin的全路径作为它的值.
- 在“用户变量”下检查是否有名为”PUB_HOSTED_URL”和”FLUTTER_STORAGE_BASE_URL”的条目,如果没有,也添加它们。
环境变量配置好了,重启电脑,打开AS右边出现flutter 代表可以创建flutter 工程了
编译报错:
在 As控制台,或命令窗口 输入flutter doctor 检查当前配置是否完善
PS C:\Users\Administrator> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 10.0.17134.165], locale zh-CN)
[X] Android toolchain – develop for Android devices
X 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.
[X] Android Studio (not installed)
[!] Connected devices
! No devices available
! Doctor found issues in 3 categories.
PS C:\Users\Administrator>
flutter 已经给我们把问题和解决方案都列了出来.
如果你的电脑以前没安装 Android SDK 和 Android Studio 的话,你看到的错误信息应该和我一致.
PS C:\Users\Administrator> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 10.0.17134.165], locale zh-CN)
[!] Android toolchain – develop for Android devices (Android SDK 28.0.1)
X Android licenses not accepted. To resolve this, run: flutter doctor –android-licenses
[√] Android Studio (version 3.1)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] Connected devices
! No devices available
! Doctor found issues in 2 categories.
Android licenses not accepted
第一个问题就是关于 Android licenses 的,flutter 也给出了解决方法,执行下面命令,然后一直输入 Y 即可
flutter doctor –android-licenses
Flutter plugin not installed 和 Dart plugin not installed
这个是提示我们 Android Studio 没有安装 Flutter 插件和 Dart 插件
让我们打开 Android Studio , 点击 Plugins,选择 Browse repositories,搜索 Flutter 进行安装,在安装 flutter时,编辑器也会帮我们安装 dart 插件
当我们安装完成后,让我们重启 Android Studio,完成编辑器配置
2.运行开源项目出现 Finished with error: FormatException: Bad UTF-8 encoding 0xc3 (at offset 169)
这是由于app的版本为release找不到keystore文件,我们只需要在app下的build.gradle文件中修改为signingConfigs.debug即可:
buildTypes {
release {
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’
}
}
Finished with error: FormatException: Bad UTF-8 encoding 0xb4 (at offset 125)
导入别的flutter 项目时出现 Flutter for Android 找不到
ctrl+shift+alt+s 打开一个界面
是因为 路径出错了,更新下就好了
添加datr Packages Libraries
点击项目中
就可以加入了
Error waiting for a debug connection: ProcessException: adb did not report forwarded port
很简单,答案说的是升级adb,其实是更新SDK Platform-Tools就可以了。