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, enteropen .zshrc
; (if using bash, enteropen .baseprofile
) Add the following code at the end of the file, wherepwd
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:
After editing the
.zshrc
(or.bashprofile
) file, save and close it, and runsource .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:
-
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
Then select the project storage address and project name.
Run Emulator#
List supported emulators
flutter emulator
The result is as follows:
Open the specified emulator
flutter emulators --launch xxx
Run the emulator
flutter run
Then select the emulator to run, as shown below:
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 seeAndroid SDK Tools(Obsolete)
, check Apply, and wait for the download to complete.
-
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 seeAndroid SDK Command-line Tools(latest)
, check Apply, and wait for the download to complete. -
Stuck at
Running Gradle task 'assembleDebug'...
when starting the emulatorBackground: 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: