Flutter environment configuration (MAC OS environment)

java installation

Address: http://www.oracle.com

  1. If you are configuring environment variables for the first time, you can use to touch .bash_profilecreate a hidden profile of .bash_profile (if you are editing an existing profile, use the open -e .bash_profilecommand):
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk12.0.1.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
  1. Use the command to take effect
source .bash_profile

python installation

Address: https://www.python.org/

View address: which python

  1. If you are configuring environment variables for the first time, you can use to touch .bash_profilecreate a hidden profile of .bash_profile (if you are editing an existing profile, use the open -e .bash_profilecommand):
# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

alias python="/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7"
The premise is that you have installed xcodeand run it before, or you will report an error afterwards

Before installing the latest version of Python3.*, let's get familiar with the python that comes with the
system. The python path that comes with the Mac system is /System/Library/Frameworks/Python.framework/Version, let's open the directory and take a look:

open /System/Library/Frameworks/Python.framework/Versions

Before installation, search to see if there is already a python3 package:

brew search python3

It already exists, we can install it directly:

brew install python3

All packages have been downloaded, but we found that two errors were reported at the end, which probably means that the formula has been established, but an unexpected error occurred when the connection was created because there was no permission. In the error message, we see a directory /usr/local/Frameworks, let's find this directory first:

open /usr/local/Frameworks

Found that this directory does not exist, then we will manually create one:

sudo mkdir /usr/local/Frameworks

After the directory is created, let's solve the permission problem:

sudo chown $(whoami):admin /usr/local/Frameworks

If no error is reported, the modification is successful. After modifying the permissions, you need to manually perform the unfinished connection creation during installation:

brew link python3

connection succeeded. Let's check the information of python3 under the current system:

brew info python3
  1. Use the command to take effect
source .bash_profile

Download flutter

It is recommended to download from the official website, the speed is not slow, URL:

https://flutter.io/setup-macos/

https://storage.googleapis.com/flutter_infra/releases/beta/macos/flutter_macos_v0.3.2-beta.zip

https://storage.googleapis.com/flutter_infra/releases/beta/macos/flutter_macos_v0.9.4-beta.zip

Configure environment variables

First unzip the flutter_macos_v0.3.2-beta.zip you just downloaded, the directory you choose to use is the app folder under the root directory

Let mac computer display the path

defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES

Or by selecting the folder Command+Cto copy, in the terminal Command+Vcan paste.

  1. Open the terminal tool, use vim to configure environment variables, the command is as follows:
vim ~/.bash_profile

or

vi ~/.bash_profile
  1. Adding a line of code to the opened file means that the flutter command can be used anywhere.

Tip: You should write this command according to the location where you decompressed the compressed package, and write your path, which may not be the same as the article.

export PATH=/Users/hfy/Desktop/flutter/bin:$PATH
  1. After the configuration is complete, you need to reload it with the source command. The specific commands are as follows:
source ~/.bash_profile

After finishing this part, even if the installation work of our flutter is completed, it cannot be developed yet. You can use the command to check whether the installation is complete.

flutter -h

4. So far, we have installed Flutter, but we don't have a development environment yet. Development also requires a lot of software and plug-in support, so what plug-ins and software are needed? We can use the commands provided by Flutter to check:

flutter doctor

5. The first step is to allow the agreement (android-licenses). The allowed method is to run the following command in the terminal: all the way to Y is enough

flutter doctor --android-licenses

Report an error

A newer version of the Android SDK is required. To update, run:
/Users/hfy/Library/Android/sdk/tools/bin/sdkmanager --update

Continue to reproduce, perform, but suggested that under /Users/***/Android/sdk/tools/bin/sdkmanager:no such file or directory.

In fact, it is sdkmanagerin an adjacent directory, but it is useless, because even if it is successfully updated, and then copied to that location, flutter doctor --android-licensesit will continue to prompt that it needs to be updated even if it is executed again , which is an infinite loop.

solution

Obviously this is not a "normal situation", and the final effective solution is as follows:

Open Android Studio-> Configure-> SDK Manager, and then in the opened interface, there are a total of three sub-interfaces, namely SDK Platforms, SDK Toolsand SDK Update Sites.

Cut to SDK Toolsthis sub-interface, find the Hide Obsolete Packagesoption slightly above the bottom of the interface , this item is checked by default, uncheck it.

In the newly appeared package list, find Android SDK Tools (Obsolete)and tick it.

Then in the lower right corner Apply, click Finishafter the installation is complete, and then click OKto exit Android Studio.

Run again this timeflutter doctor

flutter doctor --android-licenses

6. Installationbrew

https://brew.sh/

Install Homebrew on Mac

Domestic installation (available):

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

Official installation method 1:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

After running:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

The browser can't access https://raw.githubusercontent.com/Homebrew/install/master/install.sh either. You need to go over the wall. I don't have the conditions to go over the wall for the time being, so I can only change the way.

Official installation method 2

# 安装在/usr/local/目录
cd /usr/local/
# 官方命令行,安装在homebrew目录
sudo mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew

We can directly enter the following commands in the terminal (you will have to wait a while after you finish entering one, and wait for the package installation to complete)

brew install --HEAD libimobiledevice
brew install ideviceinstaller
brew install ios-deploy
brew install cocoapods
pod setup
vim ~/.bash_profile

Add two lines

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

Reload the environment

source ~/.bash_profile

.bash_profileAll configured environment

# Flutter 环境
export PATH=/Users/hfy/Desktop/flutter/bin:$PATH
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
# Flutter END

# Java 环境
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
# Java END

# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
alias python="/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7"
export PATH=/usr/local/bin:$PATH
# Python END

# HomeBrew
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
# HomeBrew END

Error 1

iOS toolchain - develop for iOS devices (Xcode 12.0.1)
    ✗ CocoaPods installed but not initialized.
        CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
        For more info, see https://flutter.io/platform-plugins
      To initialize CocoaPods, run:
        pod setup
      once to finalize CocoaPods' installation.

solve:

CocoaPods installation and usage and common problems
https://blog.csdn.net/u013195845/article/details/51330316

Execution:
First check your ruby ​​to see if it is https://gems.ruby-china.com/

gem sources -l

If it is not the source of https://gems.ruby-china.com/, add a new source and uninstall the old source;

gem sources --add https://gems.ruby-china.com/ --remove https://gems.ruby-china.org/

Execute again

sudo gem install cocoapods

Error 2

Android toolchain - develop for Android devices (Android SDK 30.0.2)
    ✗ Android license status unknown.

do it again

Error 3

Flutter (Channel beta, v0.9.4, on Mac OS X 10.15.6 19G2021, locale zh-Hans-CN)
    ✗ Downloaded executables cannot execute on host.
      See https://github.com/flutter/flutter/issues/6207 for more information

Install xcode

Both have the same configuration environment

One-time solution

open -e .bash_profile
vi ~/.bash_profile
source ~/.bash_profile

Permanent solution

open ~/.zshrc 
vi ~/.zshrc 
source ~/.zshrc

Flutter environment configuration (MAC OS environment)
Flutter environment configuration (window10 environment)

Guess you like

Origin blog.csdn.net/weixin_43764814/article/details/109485615
Recommended