Flutter environment construction guide

Flutter environment construction guide

Introduction to Flutter

Flutter is an open source mobile application development framework launched by Google, featuring cross-platform, high-fidelity, and high-performance. Developers can develop apps through the Dart language, and a set of codes runs on both iOS and Android platforms. Flutter provides a wealth of components and interfaces, and developers can quickly add Native (that is, native development, refers to the development of applications based on the platform's native language, flutter can be mixed with the platform's native language) extensions for Flutter.

Build a Flutter development environment on Windows

System Requirements

To install and run Flutter, your development environment must meet the following minimum requirements:

  • OS: Windows 7 or later (64-bit)

  • Disk space: 400 MB (disk space not including Android Studio).

  • Tools: Flutter relies on the following command-line tools ( required to be added to the PATH environment variable ).

    If you have Git for Windows installed, make sure you can run the git command in Command Prompt or PowerShell

Get the Flutter SDK

  1. Go to flutter official website to download its latest available installation package, download address

    insert image description here

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

  3. flutterFind it under the file in the Flutter installation directory flutter_console.bat, double-click to run it and start the flutter command line . Next, you can run the flutter command on the Flutter command line.insert image description here

  • Update environment variables:

    If you want to run flutter commands on the Windows system's own command line, you need to add the following environment variables to the user PATH:

    • Type "env" in the search function of the start menu, and then select Edit system environment variables
    • Check for an entry named "Path" under "User Variables":
      • If the entry exists, append the full path flutter\binof (mine is D:\flutter\bin), using ; as a separator.
      • If the entry does not exist, create a new user variable Path and flutter\binuse the full path of as its value.

    Restart Windows to apply this change.

  • Run the flutter doctor command

    Run the following command on the Flutter command line to see if any other dependencies need to be installed, and if so, install them:

    flutter doctor
    

    This command checks your environment and displays a report in the command window. The Dart SDK is already packaged in the Flutter SDK, there is no need to install Dart separately. Carefully examine the command line output for additional software that may need to be installed or further tasks to be performed.

    For example:

    [-] Android toolchain - develop for Android devices
        • Android SDK at D:\Android\sdk
        ✗ Android SDK is missing command line tools; download from https://goo.gl/XxQghQ
        • Try re-installing or updating your Android SDK,
          visit https://flutter.dev/setup/#android-setup for detailed instructions.
    

    The first time you run a flutter command (like flutter doctor), it downloads it's own dependencies and compiles itself. It will be much faster to run later. The missing dependencies need to be installed, and after the installation is complete, run flutter doctorthe command to verify whether the installation is successful.

Encountered problems and solutions

After opening flutter_console.batand flutter doctor, it will force a flashback, and the same is true for running in cmd. Referring to the solution on the Internet, it may beC:\Windows\SysWOW64\WindowsPowerShell\v1.0

It is not added to the PATH of the user variable, and it still crashes after the modification and restart.

solution:

Windows PowerShell is a command-line shell and scripting language developed by Microsoft for the Windows operating system. It is designed as a replacement for the traditional Windows Command Prompt (cmd.exe) and provides a set of advanced features for system administrators and power users.

PowerShell uses a command-line interface (CLI) based on the syntax of the C# programming language. It provides access to various system administration tasks, such as managing files and folders, configuring network settings, and interacting with the Windows registry.

One of the key features of PowerShell is its ability to automate complex tasks using scripts. PowerShell scripts are essentially text files that contain a series of commands that can be executed together to perform a specific task. This saves time and increases productivity for system administrators, who can use scripts to automate repetitive tasks and reduce the risk of errors.

PowerShell also supports the use of modules, which are collections of related commands that can be loaded into the shell on demand. This allows users to extend the functionality of PowerShell and add new commands for specific tasks.

Consider using it to provide error messages, open Windows Powershell, enter flutter doctor, and the following error message appears:

insert image description here

Reconfigure the environment variables, addD:\Download\Git\bin;D:\Download\Git\cmd;C:\Windows\System32;

Still getting an error .

After many attempts, I finally found a solution: delete the original flutter folder, and use the following command to check out the Flutter SDK directly from the Master build channel:

git clone -b master https://mirrors.tuna.tsinghua.edu.cn/git/flutter-sdk.git
./flutter-sdk/bin/flutter --version

Note : In the folder where you want to download the flutter SDK, click the right mouse button to use Git Bush here, and execute the above Git command

insert image description here

And D:\flutter\flutter-sdk\binadd to the Path of the environment variable.

Re-run in Windows Powershell flutter doctor, no more errors.

insert image description here

flutter_console.batflutter doctorIt will no longer flash back when it is running , and it can normally obtain other software that may need to be installed or further tasks that need to be performed:

insert image description here

You can continue with subsequent Android settings.

Android settings

Flutter depends on the full installation of Android Studio. Android Studio can not only manage Android platform dependencies, SDK versions, etc., but it is also one of the recommended IDEs for Flutter development.

Download and install the JDK

  1. JDK (Java Development Kit) is a Java development kit for software developers.
    • A collection of independent programs
    • Including Java tools and Java runtime environment (JRE, Java Runtime EnvironmentJava)
    • For developing and testing Java programs

insert image description here

  1. Download JDK: download link

    insert image description here

    Windows x64 Compressed Archive: compressed version, you need to configure it yourself

    Windows x64 Installer: installation version, self-configuration during installation

  2. Install JDK: Double-click the downloaded file to start the installation.

    insert image description here

  3. Check if the installation was successful:insert image description here

Download and install Android Studio

download link

Start Android Studio, and execute the "Android Studio Setup Wizard". This will install the latest Android SDK, Android SDK Platform-Tools, and Android SDK Build-Tools, which are required for Android development with Flutter.

insert image description here

The installation is complete.

In order to prevent the .android file in the C drive from being too large and the C drive becoming popular, you can create an ANDROID_EMULATOR_HOMEenvironment variable:

insert image description here

Guess you like

Origin blog.csdn.net/m0_61443432/article/details/130551717