今是昨非

今是昨非

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

Flutter Environment Installation && Running

Flutter Environment Installation && Running#

Background#

Flutter environment configuration to running, problem memo record. For example, encountering Android sdkmanager tool not found and Running Gradle task 'assembleDebug'...

Flutter Installation#

Super Slim Version#

Install directly through homebrew, may require internet access

brew install flutter

Manual, Flutter Environment Setup#

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

  • Next, extract the downloaded files and place them in the specified directory. Note: it is recommended to place them in the user's root directory, as the bin file address needs to be specified later, and this directory is less likely to change frequently.

  • Then, configure the environment variables
    Open the terminal, if using zsh, enter open .zshrc; (if using bash, enter open .baseprofile) Add the following code at the end of the file, where pwd is the address of the flutter/bin file that was just extracted,

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

    At the same time, due to reasons in China, you can also add the following two environment variables

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

    As shown in the figure below:

    wx20210716-170052.png

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

    source .zshrc
    // If you edited .bashprofile, enter source .bashprofile
    

    Then run flutter doctor to determine if Flutter is installed properly.

Editor Installation#

  • Android Studio
    After downloading and installing Android Studio, there are three places that need to be installed

    • SDK Manager, install SDK Platforms, add the required Android versions based on actual needs
    • AVD Manager, add Android emulators
    • Plugins, add Flutter and Dart plugins

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

  • Xcode, download and install directly, then open it once.

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

Verify Environment#

Enter flutter doctor and determine if the environment is properly installed based on the prompts. You may encounter problems, which can be referred to in the problem record below.

Enter flutter doctor --android-licenses, there will be a prompt to choose y/N, choose y for all.

Create Project#

Create a Flutter project using VSCode, open VSCode (remember to install the Flutter plugin), and press CMD+Shift+P to invoke the shortcut command. Enter Flutter and select Flutter: New Application Project, as shown below

wecom20210716-172146@2x.png

Then select the project storage address and project name.

Run Emulator#

List supported emulators


flutter emulator

The result is as follows:

screen shot 2021-07-16 at 13.50.49.png

Open the specified emulator


flutter emulators --launch xxx

Run the emulator


flutter run

Then select the emulator to run, as shown below:

wx20210716-151358@2x.png

Problem Record#

  • When running flutter doctor, error: Android sdkmanager tool not found

    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, error: Failed to install android-sdk: “java.lang.NoClassDefFoundError:

    Solution: Open Android Studio, click Config->SDK Manager, select SDK Tools, uncheck Hide Obsolete Packages, you will 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, when selecting the Android emulator, it always gets stuck at Running Gradle task 'assembleDebug'...

    Reason: Gradle's Maven repository is located overseas, so you need to use the mirror address provided by Aliyun.

    Solution:

    Modify the andriod/build.gradle file, change 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.