This is the third day of my participation in Gwen Challenge

Note: This article is republished from the personal public number (Island front island)

Flutter is Google’s mobile UI framework for quickly building high quality native user interfaces and applications for mobile (iOS & Android), Web, desktop, and embedded devices from a single code base.


  • Get rid of the AS Ide to use the command line development environment

Why leave the Android Studio Ide?

Why did I want to write Flutter without Android Studio Ide?

This is because, by the time all the required environments and SDK for the Android Studio Ide are installed, it takes up about 6-8GB of disk space. This is too much for me! Afraid of! Some! ! So I started to try to develop Flutter without the Android Studio Ide and only use VS Code. Fortunately, Flutter officially supports VS Code. For details, see flutterChina.club

How to create an Android VIRTUAL machine from the command line?

Make sure that the Android commands are available. References to the configuration, commands, and environment of the Flutter are AS follows

However, if you want to create Android virtual machines from the command line, you will need to update the required support packages using sdkManager

#The emulator and build - the tools; 29.0.0 (I'm using the android version 29 as an example)sdkmanager "emulator" "build-tools; 29.0.0"Copy the code

If you are familiar with the command line, it will not be a big problem. Here, take care of the friends who are not familiar with the command line and want to install force

Old version commands

Create an AVD virtual machine (old version command)

# -t targetID android create avd -n tAndroid -t 1Copy the code

How do I get targetID? Command line -> Enter android list target to list the versions of the Android API that have been downloaded locally

android list target
Copy the code

Older versions of the command, if executed, will report an error. It tells you that flag ‘-t’ is not valid for ‘create AVD ‘.



(Old version command – execution error)

Current version command

So how does the new command work? Basically not much has been changed from the -t flag to the -k flag, which says which version of the system image package and API will be used

android create avd -n tAndroid -k 1
Copy the code

Creating a VM

If you have downloaded the corresponding system API (Platforms; Android-29), then this command will tell you when executed

Need: system – images; android-29; google_apis; X86_64, which stands for Android image and related apis



(Command prompt missing mirror)

Then download the package

sdkmanager "system-images; android-29; google_apis; x86_64"Copy the code

After the download is complete, run the command again. In this case, the -k parameter is the full name of the downloaded image

android create avd -n tAndroid -k "system-images; android-29; google_apis; x86_64"Copy the code

Do you need to create custom hardware configurations? The default value is [no] and you can press Enter to complete the configuration. The default virtual machine is created with full API support, but with a screen width of 320px and a DPR of 1.

After a few moments, the virtual machine is created.

How do I start a VM

Remember the support package emulator you downloaded in the first place? You’ll need it to start the Android virtual machine.

Don’t know how to use it? OK, no problem. Type emulator on the command line and the result will tell you to use @virtual machine name or -avd virtual machine name.

emulator @tAndroid 
# or
emulator -avd tAndroid
Copy the code

The first startup is most likely to encounter the following error

But don’t worry, there’s one more thing you need to do:

  1. Go to the location of your configured SDK folder, go to emulator. Exe in the Emulator folder, and right-click to create a shortcut.
  2. Then cut it and go to the Tools folder under the SDK folder and right-click paste.

Then you’ll notice there’s an emulator.exe too!! What’s going on here? Real Monkey King? !

Don’t panic!! Just rename the original emulator.exe and remove the new emulator.exe shortcut.

And then re-execute it

emulator -avd tAndroid
Copy the code

You are bound to get the following error

WHPX & HAXM

Big brother, why did you make a mistake again?

What is WHPX?

What is HAXM?

Take your time and read the hints carefully:

Hardware acceleration required to use emulation (VIRTUAL machine) Please ensure that Windows Hypervisor Platform (WHPX) is properly installed and CPU acceleration is available Status: Hardware Acceleration Execution Manager (HAXM) is not installed on this computer if you are using an Intel CPU: Check that virtualization is enabled in the BIOS and that HAXM is installed and available. If you are using AN AMD CPU or need to run with hyper-V-based applications such as Docker, we recommend that you use the Windows Hypervisor platform

So, do you know what WHPX & HAXM is after watching it?

At this time as long as download HAXM support package, and in the BIOS open motherboard virtualization support can solve the problem!

Google/Bing/Baidu your own motherboard virtualization support options where, then turn on OK!

Download the HAXM support package

sdkmanager "extras; intel; Hardware_Accelerated_Execution_Manager"Copy the code

Once enabled, find extras\ Intel \Hardware_Accelerated_Execution_Manager in your SDK folder

If the installation fails, virtualization support is not enabled successfully.

After the installation is successful, run -> emulator@tandroid again and wait

emulator -avd tAndroid
Copy the code



(Starting the VM)

The exciting time is coming!

Don’t get excited! Even though the virtual machine was successfully created and started.

However, the ability to establish a connection to the development project is questionable.

Run the following commands to check the device

adb devices
Copy the code
flutter devices
Copy the code

Both can be identified as Android virtual machines, so you can use virtual machines for development


conclusion

  • Step by step, take note of the pit, so that the process can be used later.
  • When something goes wrong, don’t panic. Error messages most of the time tell you exactly what happened.
  • Learning how to use search tools and using them wisely can help you reduce your chances of seeing spam articles.

Get rid of the AS Ide to use the command line development environment