Flutter environment construction and process issues

Prerequisite: Android Studio and Xcode have been installed correctly

1. Get the Flutter SDK

1. Download: https://docs.flutter.dev/development/tools/sdk/releases?tab=macos#macos
2. Unzip the installation package

2. Configuration environment

1. Open the environment configuration file:
open ~/.bash_profile
If there is no bash_profile file, create a new one:
touch .bash_profile
2. Add environment configuration:

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=SDK解压的路径/flutter/bin:$PATH

For example: export PATH=/Users/xxx/flutter/bin:$PATH

Notice:

update environment variables

You can only update the PATH variable for the current session from the command line, however, what you may want is to update this variable permanently so that you can run fluttercommands in any terminal session.

The steps to permanently modify this variable for all terminal sessions are computer system specific. Typically you would add commands that set environment variables to the file that is executed when opening a new window. For example

  1. Identify the directory of your Flutter SDK, which you will use in step 3.
  2. Open (or create) $HOME/.bash_profile. The file path and filename may be different on your machine.
  3. Add the following line and change [PATH_TO_FLUTTER_GIT_DIRECTORY]to the path of the git repo where Flutter was cloned:
export PUB_HOSTED_URL=https://pub.flutter-io.cn //国内用户需要设置
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn //国内用户需要设置
export PATH=PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH


Note: PATH_TO_FLUTTER_GIT_DIRECTORYFor your flutter path, such as "~/document/code"

 export PATH=~/document/code/flutter/bin:$PATH


  1. Run source $HOME/.bash_profileto refresh the current terminal window.

Note: If you are using zsh, ~/.bash_profileit will . The solution is to modify it ~/.zshrcand add: source ~/.bash_profile

flutter/bin5. Verify that the directory is already in PATH by running the command:

echo $PATH


3. Check the environment

1.运行:flutter -h

Question 1: When running flutter -h, an error is reported:

VersionCheckError: Command exited with code 128: git fetch __flutter_version_check__ stable Standard error: fatal: unable to access 'https://github.com/flutter/flutter.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
Solution:
Install flutter in Android studio and
run flutter -h again

2. Run: flutter doctor

Question two:

![image.png](https://upload-images.jianshu.io/upload_images/9149864-e726601df2a7711a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 以上提示Android某些证书在SDK30.0.3的版本中不被允许 解决方案:
run: flutter doctor --android-licenses
根据提示全部选择y,回车
run again: flutter
doctor`

Question 3: When entering flutter doctor --android-licenses, the following exception is reported:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156) at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75) at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81) at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73) at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48) Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 5 more
Solution:
1. Terminal input: open ~/.bash_profile to open this problem, if not, touch ~/.bash_profile to create this problem
2. Input in the file: export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents /Home, that is, configure your Java environment variable
3. After saving, enter in the terminal: source .bash_profile, let the environment variable take effect immediately
4. Then run flutter doctor --android-licenses and keep selecting y according to the prompt,
5. Run again flutter doctor

Question 4: Enter the flutter doctor exception prompt:

cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`

According to the prompt: go to sdkmanager to install cmdline-tools;latest
The solution is as shown in the figure below, check and install:

Run flutter doctor again after installation

at last

If you want to become an architect or want to break through the 20-30K salary range, then don't be limited to coding and business, but you must be able to select models, expand, and improve programming thinking. In addition, a good career plan is also very important, and the habit of learning is very important, but the most important thing is to be able to persevere. Any plan that cannot be implemented consistently is empty talk.

If you have no direction, here I would like to share with you a set of "Advanced Notes on the Eight Major Modules of Android" written by the senior architect of Ali, to help you organize the messy, scattered and fragmented knowledge systematically, so that you can systematically and efficiently Master the various knowledge points of Android development.
insert image description here
Compared with the fragmented content we usually read, the knowledge points of this note are more systematic, easier to understand and remember, and are arranged strictly according to the knowledge system.

Full set of video materials:

1. Interview collection

insert image description here
2. Source code analysis collection
insert image description here

3. The collection of open source frameworks
insert image description here
welcomes everyone to support with one click and three links. If you need the information in the article, directly scan the CSDN official certification WeChat card at the end of the article to get it for free↓↓↓

Guess you like

Origin blog.csdn.net/weixin_43440181/article/details/129714289