preface

This article mainly introduces the process of building Flutter in Mac environment and some possible solutions. Flutter officials already provide a comprehensive installation process, so here are some solutions to environmental problems you may encounter.

Environment set up

The JDK, Android SDK and the Flutter SDK must be installed in the Flutter development environment. These three basic dependencies are required. We can install the Flutter in parallel to save some time.

Install the Flutter

When using Flutter in China, due to the limited network environment, we can access domestic images to speed up the operation of Flutter. There are also hardware requirements for Flutter application. Please refer to the official website for examples.

  1. Configure environment variables.

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

    You need to configure different files according to the shell tool. For bash and ZSH operations, environment variables are configured in the user directory.bash_profile when bash is used and in the user directory.zshrc when ZSH is used. If not, create and edit them accordingly.

  • bash

      vim ~/.bash_profile
    Copy the code
  • zsh

      vim ~/.zshrc
    Copy the code

  1. Download the latest available flutter installation package from the Flutter website.

  2. Unzip the installation package to the directory you want to install.

    CD ~ / development unzip ~ / Downloads/flutter_macos_v0. 5.1 beta. ZipCopy the code
  3. Add a Flutter environment variable

    Add the following configuration in the configuration file in Step 1

At this point, the configuration of Flutter ends.

Installing the Android Environment

I set up the Android development environment in local development, so this is only the Android configuration. What we really need is the Android SDK, which we usually install by installing Android Studio so that we can choose to use AS AS our development IDE.

  1. download

    Download AS from the Android official website.

  2. The installation

    The version I installed is AS 3.6 Preview. During the installation process, IT may be found that the SDK installation fails and the server access times out, resulting in the failure of the subsequent software. The solutions are as follows:

  • Cloud Server Access

    This is by far the easiest way I have found to solve the network problem, using a cloud server for network forwarding. (Link) The package that we need to download is mainly under the domain name dl.google.com. Find the IP address that can be forwarded and configure host to solve the problem.

      vim /etc/hosts
    Copy the code

IP may only be temporary, but if you find that the download is slow, you can find a faster IP in the link above, and switch the following host configuration.Copy the code
  • Over the wall

    Buying or building a ladder to download services from the Internet can be expensive and time-consuming.

  • Configure the agent

You need to query the specific proxy server.

The Android SDK itself is quite large, so it may take a long time to download. As long as no error is reported, the SDK is successfully installed. Once the network problem is solved, the rest of the content is relatively easy, just click on the next step.

Install the JDK

  1. The installation

    To develop Flutter applications on Android, the JDK must be installed, and the JDK version installed must be compatible with the Android version. Otherwise, the application will not work. Self-test Android 10 for JDK8. The JDK version cannot be too high. (Adaptation table)

  1. detection

After the installation, run Java -version on the CLI to check whether the installation is successful. If the Java directive is invalid, you need to configure the environment variables.

Installing the Android Emulator

After completing the above steps, the environment is basically taken care of. Generally, we can debug applications by linking devices or using an Android emulator. Experientially, the simulator is a little better, and we can test different device models.

  1. Installing the emulator

    AS has its own simulator. You can click the mobile phone button in the upper right corner of the IDE and download the corresponding simulator device according to your own needs.

  1. Running simulator

    After downloading the simulator, click Run. After opening the simulator, open the developer option first and then USB debugging. The steps are as follows. When this is done, simulator debugging is over.

Run the application

It’s time to configure our IDE. The development process can be either Android Studio or VS Code. To support Flutter, you need to install the Flutter extension for the IDE.

  1. AS the configuration

FLutter can be searched, installed, and restarted in the AS Plugin. After the installation is successful, create a new project in the install Flutter official step, select the entry file above the IDE and run it.

  1. VS code configuration

Install the Flutter and Dart plug-ins in VS Code. Enter flutter run at the end of the command. Observing the simulator, you can see that the application starts normally.

conclusion

During the whole process of setting up the environment, there were a lot of problems. Finally, it was found that the software package was not successfully installed and the Android version was incompatible with JDK version because of network problems. All sorts of searches led to a viable solution, which eventually led to the Flutter application.

Our common future consumer terminal devices are bound to be lighter and more portable. At present, the market of mobile devices is very broad, basically occupying the main market of consumers. As a developer, it’s important to know something about current mobile development.

FLutter, as a cross-platform native development framework, is currently in the hot market and has many enterprise applications that can significantly improve productivity. Why don’t you take a look?