My deployment machine CentOS7 did not install the graphical desktop, run the emulator times QT, XCB error (welcome to encounter the same problem students discuss together), so install the emulator in Docker. The following is the setup process.

This is an intermediate level of difficulty. You need to know the following knowledge in advance

  • Android emulators, x86 and ARM
  • Linux basic operations, change environment variables
  • Docker basic operations
  • VNC and noVNC

Environment to prepare

  • Linux systems that support KVM (x86 emulators must support KVM, arm does not)
  • Docker(supported by native environment)
  • Science and the Internet

Install the simulator command line tool

  1. Emulators depend on Java environment, first install JDK8. Official portal

Or use the command line installation:

sudo apt-get update
sudo apt-get install openjdk-8-jdk

# centosYum install - y Java - 1.8.0 comes with - its - devel. X86_64Copy the code
  1. Download the Android simulator Tools. Official Portal

3. Add the JAVA and ANDROID_HOME environment variables.

Run the Docker image

  1. Install Docker, follow the official portal installation all the way. For offline installation, please refer to the back stepping pit record.
  2. Pull the mirror
docker pull thyrlian/android-sdk-vnc
Copy the code
  1. Start the container
docker run --privileged --network host -v /dev/kvm:/dev/kvm -v $ANDROID_HOME:/opt/android-sdk thyrlian/android-sdk-vnc
Copy the code
parameter explain
-v /dev/kvm:/dev/kvm | required, share the KVM of the deployment machine
-v $ANDROID_HOME:/opt/android-sdk | Shared deployment machine download simulator
–network host | Use the network of the deployer
  1. Use Screen Sharing or VNC Viewer to connect to VNC ://IP:5901 on the local computer, and you can see a minimalist Linux desktop.

Download and run the simulator

Tip: The following installation commands require environment variables to work.

# 1. View the installation list
sdkmanager --list
# 2. Install Platform-Tools
sdkmanager "platform-tools"
# 3. Install API30 to support both x86 and ARM
sdkmanager "platforms; android-30"
# 4. Install the simulator image
sdkmanager "system-images; android-30; google_apis; x86_64"
# 5. Install the emulator run file
sdkmanager "emulator"
# 6. Instantiate an Android machine
avdmanager create avd -n android30 -k "system-images; android-30; google_apis; x86_64"
# 7. Run the Android emulator
emulator -avd android30 -noaudio -no-boot-anim -gpu off
# 8. Install apK
adb install -r name.apk

Copy the code

After the above successful installation, we should see the emulator appear on the desktop.

parameter explain
-n android30 | name
-noaudio | Disables audio
-no-boot-anim | Do not start animation

Iv. NoVNC construction

If you do not use the above Docker image, first install VNC, tutorial please search.

  1. Download the noVNC file official portal.
  2. Decompress it and run the following command, then go to http://IP:6081 in your browser and enter the password Android to see the final result.
./utils/novnc_proxy --listen 6081 --vnc IP:5901
Copy the code
parameter explain
listen 6081 | Specifies the port number to access
IP:5901 | IP is the IP address of the machine to start the emulator, and 5901 is the port number of the VNC runtime

Five, stepping pit record

  1. Official Docker cannot add repo, the network is unreachable.

Solution 1: Download the RPM offline package and install it on the CLI.

Solution 2: Download the RPM offline package, nginx starts the access file service, change the docker-ce.repo after the local source installation.

  1. Installing Docker dependencies is incomplete

Solution: Because there is a problem with the yum source of the deployment machine, update the source and install all dependencies.

  1. After the emulator is installed, the base image cannot be connected using VNC after the commit.

Solution: Mount the Android-SDK of the base image to the deployment machine and use the locally downloaded file.

  1. Android-sdk cannot be installed due to firewall restrictions on the deployed machine.

Solution: Start the same image on your development machine, install the SDK and copy the files to the deployment machine.

  1. The noVNC command fails to be executed

Solution: the first time you execute the command automatically download Websockify failed, you can go to the official portal download, put under utils.

Six, reference

  1. Andresand.medium.com/android-emu…
  2. Developer.android.com/studio/run/…
  3. Developer.android.com/studio/comm…
  4. www.cnblogs.com/yuezhimi/p/…
  5. www.jianshu.com/p/9d81dd37f…