Flutter installation, configuration, various wonderful problems
1. About environment variables
Since it is necessary to modify the environment variables frequently, here is an explanation:
Enter: Control Panel --> System --> Advanced System Settings --> Environment Variables
or directly win+s to search for h.
-
About user variables and system variables:
System variables : work for all users
User variables : work for the current user
优先级:系统变量>用户变量
, that is to say, in the case of the same variable, the system variable takes precedence. Which setting to use is up to you. -
About the path setting
Different systems have different setting methods, win7 is to add a semicolon, and win10 is to edit directly (without a semicolon), for example:
win7: abc\bin;cde\bin;
win10: set abc\bin and cde separately \bin
2. Installation
1. Install git and Android Studio
Since flutter relies on git and Android Studio, you need to install git and Android Studio first.
Install git
to install Android Studio.
Android Studio needs to install the Android SDK and configure the virtual machine. During
the installation process, write down the Android Studio directory.
After installation, the Android SDK directory will normally be In: C:\Users\Administrator\AppData\Local\Android\Sdk (you need to open the function of viewing hidden files)
2. Install flutter
2.1 Add environment variables
Due to domestic access, it may be very slow, first add the environment variable:
PUB_HOSTED_URL value is https://pub.flutter-io.cn
FLUTTER_STORAGE_BASE_URL value is https://storage.flutter-io.cn
2.2 Download and install flutter
Go to https://github.com/flutter/flutter clone a copy to the local.
Then go to the environment variable, edit the path, increase flutter安装目录\bin
, for example, mine is D:\Programs\flutter\bin
.
At this time, you can use the flutter command, open cmd, enter flutter doctor
to view the current installation status, and solve problems one by one.
3. Install the flutter plugin in the editor
You can use both Android Studio and VSCode, but you need to install the flutter and dart plug-ins. The specific method will not be introduced. You can directly install the flutter plug-in. During the installation process, you will be prompted whether to install dart, just click Install.
Three, the problem
1、no devices
Execute in sequence:
1.1 Add ANDROID_HOME to the environment variable
Value: C:\Users\Administrator\AppData\Local\Android\Sdk (Android sdk location, location may be different)
1.2 Add 2 values in the path:
%ANDROID_HOME%\platform-tools
%ANDROID_HOME%\tools
1.3 Open cmd, or enter in the Android studio terminal
Input flutter config --android-sdk "你的android sdk位置"
Input flutter config --android-studio-dir "你的android studio位置"
For example, flutter config --android-sdk “C:\Users\Administrator\AppData\Local\Android\Sdk”
If Setting “android-sdk” value to “…” appears, it means success, restart Android studio
1.4 Change adb version
If none of the above 3 steps can solve it, then check your adb version, open cmd, and enter to adb version
view the version. If it is greater than 1.0.40, there may be problems, and replacing 1.0.40 can solve it! This step stuck me for 2 days! !
1.0.40 download link: https://089u.com/dir/15828161-39450780-b6f4bc
After downloading, copy the three files adb.exe, AdbWinApi.dll, and AdbWinUsbApi.dll to android sdk位置\platform-tools
replace them.
If it prompts that it is in use, kill the process of abd.exe and replace it.
2. Flutter run is very slow, or stuck in Running Gradle task'assembleDebug'...
Open 你的flutter安装目录\packages\flutter_tools\gradle\flutter.gradle
and modify the red box part:
add code:
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:4.1.0'
}
}
allprojects {
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' }
}
}
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
apply plugin: FlutterPlugin
class FlutterPlugin implements Plugin<Project> {
//private static final String DEFAULT_MAVEN_HOST = "https://storage.googleapis.com";
private static final String DEFAULT_MAVEN_HOST = "https://storage.flutter-io.cn";
3、Could not reserve enough space for 1572864KB object heap
Open C:\Users\Administrator\.gradle\gradle.properties
, if not gradle.properties
, create a new file, the suffix is properties, and then add the code:
org.gradle.jvmargs=-Xmx512M
org.gradle.daemon=false
4、Detected ADB
unsolved!
It means that the adb version is too old, but I still can't update to the latest version, if you solve it, please let me know.