今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

Flutter Environment Installation && Running

Flutter Environment Installation && Running#

Background#

Memo record of Flutter environment configuration and running, including issues encountered such as "Android sdkmanager tool not found" and "Running Gradle task 'assembleDebug'..."

Flutter Installation#

Super Minimal Version#

Install directly through homebrew, internet connection may be required.

brew install flutter

Manual, Flutter Environment Setup#

  • First, download the Flutter installation package from the following link: https://flutter.dev/docs/development/tools/sdk/releases?tab=macos

  • Next, extract the downloaded files and place them in a specified directory. It is recommended to place them in the user's root directory as the bin file address needs to be specified later. This directory should preferably remain unchanged.

  • Then, configure the environment variables.
    Open the terminal and if using zsh, enter open .zshrc; (if using bash, enter open .baseprofile). Add the following code at the end of the file, where pwd represents the address of the previously extracted flutter/bin files:

    export PATH="$PATH:`pwd`/flutter/bin"
    

    Additionally, due to reasons in China, the following two environment variables can also be added:

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

    As shown in the image below:

    wx20210716-170052.png

    After editing the .zshrc (or .bashprofile) file, save and close it, then run:

    source .zshrc
    // If editing .bashprofile, enter source .bashprofile
    

    Finally, run flutter doctor to check if Flutter is installed correctly.

Editor Installation#

  • Android Studio
    After downloading and installing Android Studio, there are three additional installations required:

    • SDK Manager: Install SDK Platforms and add the necessary Android versions based on your needs.
    • AVD Manager: Add Android emulators.
    • Plugins: Add Flutter and Dart plugins.

    As shown in the images below:
    wecom20210716-170945.png
    wecom20210716-171251.png
    wecom20210716-171234.png
    wx20210716-170813.png

  • Xcode: Download and install Xcode, then open it once.

  • VSCode: Open the plugin interface of VSCode, search for Flutter, and install it.

Verify Environment#

Enter flutter doctor to check if the environment is properly installed. You may encounter issues, which can be referred to in the problem record below.

Enter flutter doctor --android-licenses and select y/N when prompted. Choose y for all prompts.

Create Project#

Create a Flutter project using VSCode. Open VSCode (make sure to install the Flutter plugin) and press CMD+Shift+P to bring up the quick command menu. Enter Flutter and select Flutter: New Application Project, as shown below:

wecom20210716-172146@2x.png

Then, choose the project directory and name.

Run Emulator#

List supported emulators:


flutter emulator

The result will be as follows:

screen shot 2021-07-16 at 13.50.49.png

Open a specific emulator:


flutter emulators --launch xxx

Run the emulator:


flutter run

Then, select the desired emulator to run, as shown below:

wx20210716-151358@2x.png

Problem Record#

  • When running flutter doctor, the error "Android sdkmanager tool not found" is encountered.

    Solution: Open Android Studio, click Config -> SDK Manager, select SDK Tools, uncheck "Hide Obsolete Packages" at the bottom, then you will be able to see "Android SDK Tools (Obsolete)". Check Apply and wait for the download to complete.

    wx20210716-153139@2x.png

  • When running flutter doctor --android-licenses, the error "Failed to install android-sdk: “java.lang.NoClassDefFoundError:`" is encountered.

    Solution: Open Android Studio, click Config -> SDK Manager, select SDK Tools, uncheck "Hide Obsolete Packages", then you will be able to see "Android SDK Command-line Tools (latest)". Check Apply and wait for the download to complete.

    wx20210716-153629@2x.png

  • Stuck at "Running Gradle task 'assembleDebug'" when starting the emulator.

    Background: After configuring the Flutter environment and selecting an Android emulator, it gets stuck at "Running Gradle task 'assembleDebug'".

    Cause: Gradle's Maven repository is located overseas, so the Alibaba Cloud mirror address needs to be used.

    Solution:

    Modify the andriod/build.gradle file, change the repositories to:

    
    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' }
    
    

    As shown below:
    wx20210716-151922@2x.png

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.