Mac flutter creation process and problems encountered

created at 07-03-2021 views: 11

Although there are tutorials on the Internet, there are some problems encountered in the process. These problems are not included in the tutorials, so I write this article to record.

1. Open the terminal

2.clone flutter

command:

git clone -b beta https://github.com/flutter/flutter.git

At this step, the terminal reports an error:

error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

solution:

3. Open (or create) .bash_profile

3.1 Open

Terminal input:

open -e .bash_profile

If it cannot be opened successfully, create it

3.2 Create

1. Enter the current user's home directory (the default is)

cd ~  //or cd /Users/username

4. Update environment variables

Opening bash_profile is to update the environment variables permanently, once and for all. Please read the explanation and pay attention to add the code to the opened bash_profile according to your needs.

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

Explanation: Because some flutter commands need to be connected to the Internet to obtain data, if you are visiting in China, direct access may not succeed due to well-known reasons. The PUB_HOSTED_URL and FLUTTER_STORAGE_BASE_URL above are temporary mirror images built by Google for domestic developers. You can also leave it alone, if you can get over the wall. If you can't, you can copy the above code directly

export PATH= PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH

Note: PATH_TO_FLUTTER_GIT_DIRECTORY is your flutter path, such as in the current user path. If you are not sure, you can click "Go" --> "Personal" in the menu on the mac, and then find if there is a flutter folder in this folder. If so, yours should be written like this:

export PATH= /Users/[username]/flutter/bin:$PATH

Then enter the following command to update the environment variables just configured:

source .bash_profile

Then enter the following command to verify whether the directory is already in the PATH by running the flutter/bin command:

echo $PATH

If you see flutter, it is configured

5. Run flutter doctor

Enter the following command to see if there are any dependencies to install:

flutter doctor

If you are reminded to update flutter, I don't want to see the warning so I will update it immediately.

flutter upgrade

Error 1:

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.io/setup/#android-setup for detailed instructions).
      If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.

This reminds me to install android studio and set the environment variable $ANDROID_HOME.

So I followed the prompts to open https://developer.android.com/studio/index.html, and downloaded and installed android studio.

It is best to run android studio after installation to install andriod sdk. After running, click the next step according to the prompt on the interface. If there is no sdk, it will be prompted to install, just click. Remember to check the installation path, usually the path is in the current user's Library folder.

After installing the SDK, you can close the android studio.

Then open bash_profile

open -e .bash_profile

Add in bash_profile

export ANDROID_HOME="/Users/用户名/Library/Android/sdk" //android sdk directory, replace with your own
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools

Update configuration

source .bash_profile

Then run

flutter doctor

Look at this item and still report an error. ok still has an error, the error is as follows:

[!] Android toolchain - develop for Android devices (Android SDK 28.0.2)
    ✗ Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

Follow the prompts to run:

flutter doctor --android-licenses

Then follow the prompts y, y until the end.

Error 2:

[!] iOS toolchain - develop for iOS devices
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    ✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
    ✗ CocoaPods not installed.
        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 install:
        brew install cocoapods
        pod setup

Still according to the prompt, I went to the App Store to install xcode.

After installation, run according to the previous error message:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

then

brew install --HEAD libimobiledevice

and then

brew install ideviceinstaller
brew install ios-deploy
pod setup

I got an error when I got here:

[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress

Cloning into 'master'...
remote: Counting objects: 2353094, done.        
remote: Compressing objects: 100% (450/450), done.        
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

Just get an accelerator for this.

Run doctor again

flutter doctor

ios still reports an error:

[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    ✗ Missing Xcode dependency: Python module "six".
      Install via 'pip install six' or 'sudo easy_install six'.

Enter 'pip install six' or 'sudo easy_install six' as prompted. Then run the doctor again, and there is no error in my ios. Only the error in error 3 is left.

Error 3:

[✓] Android Studio (version 3.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.

Two plugins are missing in android studio. We open andriod studio.

  1. Click preferences
  2. Search plugins
  3. Search flutter
  4. Click Install

A pop-up prompts to install dart, agree. After the installation is complete, restart andriod studio.

Conclusion

When the doctor has no errors, it is installed. But in order to facilitate development, we also need to configure the editor. Since this is relatively easy and does not make mistakes, I will not write it. Please refer to the document yourself.

created at:07-03-2021
edited at: 07-04-2021: