Flutter environment configuration

First, use a mirror

Since access to Flutter may sometimes be restricted in China, Flutter officials have created a temporary mirror for Chinese developers who can add the following environment variables to their user environment variables:

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
Copy the code

Configure the Git environment

Git – Downloading Package (git-scm.com)

Git installation is required to install Flutter

Configure the Java environment

Java SE Development Kit 8 – Downloads (oracle.com)

Flutter requires a Java environment. Just download and install Flutter.

Obtain the Flutter SDK

  1. Go to the Flutter website to download the latest available installation package and click Download.

    Note that the channel version of Flutter is subject to change. Please refer to the Website of Flutter. In addition, you may need to climb the wall to get the list or download the package in Mainland China. Readers can also download the package from the Flutter Github project.

  2. Decompress the installation package zip to the path where you want to install the Flutter SDK (e.g. C:\ SRC \ Flutter; Note that do not install flutter into a path that requires some high permissions such as C:\Program Files\).

  3. Go to the Flutter file in the Flutter installation directory and double-click flutter_console.bat to run and start the Flutter command line. Then you can run the Flutter command on the Flutter command line.

4.1 Updating Environment Variables

To run the flutter command on a terminal, you need to add the following environment variables to the system PATH:

  • Go to Control Panel > User Accounts > User Accounts > Change My Environment Variables
  • Check for an entry named “Path” under “User Variables” :
    • If the entry exists, appendflutter\binTo the full path of;As a separator.
    • If the entry does not exist, create a new user variablePathAnd thenflutter\binAs its value.

Restart Windows to apply this change

4.2 Run flutter Doctor

flutter doctor
Copy the code

The first time a flutter command (such as a flutter Doctor) is run, it downloads its own dependencies and compiles them. It will run much faster later.

Install Android Studio

Flutter requires Android Studio to be installed and configured:

  1. Download and install Android Studio.
  2. Start Android Studio, and then execute the Android Studio Installation Wizard. This will install the latest Android SDK, Android SDK platform tools and Android SDK build tools, which are required when Flutter is developed for Android

Android Studio mirror site

AndroidDevTools – Android SDK Download Android Studio download Gradle download SDK Tools download

In view of the wall, Android Studio can be downloaded from the mirror site

Download the official version 4.1.3. The higher version 4.2.0 is not currently recognized by Flutter

Set up your Android device

To be ready to run and test your Flutter application on an Android device, you need Android 4.1 (API Level 16) or higher.

  1. Enable developer options and USB debugging on your device. Detailed instructions can be found in the Android documentation.
  2. Use USB to plug your phone into your computer. If your device appears, authorize your computer to access your device.
  3. In the terminal, runflutter devicesCommand to verify that Flutter recognizes the Android device you are connected to.
  4. Run and start your applicationflutter run.

By default, the Android SDK version that Flutter uses is based on your ADB tool version. If you want Flutter to use a different version of the Android SDK, you must set the ANDROID_HOME environment variable to the SDK installation directory.

Setting up the Android Emulator

To prepare to run and test your Flutter application on an Android emulator, follow these steps:

  1. Enable VM Acceleration on your machine.

  2. Start Android Studio>Tools>Android>AVD Manager and select Create Virtual Device.

  3. Select a device and select Next.

  4. Select one or more system images for the version of Android you want to emulate, and then select Next. X86 or x86_64 image is recommended.

  5. In Emulated Performance, select Hardware-gles 2.0 to enable Hardware acceleration.

  6. Verify that the AVD configuration is correct, then select Finish.

    For more information on the above steps, see Managing AVDs.

  7. In Android Virtual Device Manager, click Run on the toolbar. The emulator starts and displays a splash screen for the selected operating system version or device.

  8. Run Flutter Run to start your device. The connected device name is Android SDK built for , where platform is the chip family, such as x86.

Six, check again

flutter doctor
Copy the code

Note: it appears in the picture! Warning does not affect the running of the program. If an X appears, the environment is wrong and corrective action is required.

For example, if you don’t have an Android certificate after installing Android Studio, you’ll need to run:

flutter doctor --android-licenses
Copy the code

You just need to do the right thing until running the FLUTTER doctor command doesn’t show the X sign!

Configure the editor

7.1 Installing the Flutter Plug-in

  1. Start VS Code
  2. Call the View > Command Palette…
  3. Type ‘Install’ and select Extensions: Install Extension Action
  4. Enter in the search boxflutterSelect ‘Flutter’ in the list of search results and clickInstall
  5. chooseOKRestart VS Code

conclusion

This is the end of environment configuration. Since I use Windows, I have configured the Windows environment. If you need to configure other environments, you can check it on the official website.

Getting started: Build Flutter Development Environment on Windows – Flutter Chinese (FlutterChina.club)