简体   繁体   中英

Suppress launching emulator using Android within VirtualBox

Description

I am running Android-x86 7.1 using VirtualBox. I want to adb connect from the host to the guest. I experience a very random behavior when it comes to adb devices. As soon as the virtual machine runs there is a chance that an emulator called emulator-5554 appears. Sometimes it is listed, sometimes it is not. Connecting to the device using adb connect 127.0.0.1 results in the following:

  • If emulator-5554 is listed the device 127.0.0.1:5555 is marked offline and it cannot be used. emulator-5554 must be used then.
  • If emulator-5554 is not listed I can use the device 127.0.0.1:5555 without any problem.

adb devices -l shows that the emulator is coming from the virtual machine: device product:android_x86_64 model:VirtualBox device:x86_64 transport_id:1

Problem

Even though emulator-5554 works fine and I can communicate with the virtual machine I cannot rely on this due to I want to automate things. 127.0.0.1 is given by my VirtualBox network configuration. The name emulator-5554 seems random and might change. Therefore I need to use adb connect 127.0.0.1 which is not possible when the emulator is online.

VirtualBox configuration

Network settings

  • Only adapter 1 is active, adapter 2-4 are not enabled
  • Attatched to: NAT
  • Port forwarding :
    • Name: ADB#1 , Protocol: TCP , Host IP: 127.0.0.1 , Host Port: 5555 , Guest IP: 10.0.2.15 , Guest Port: 5555
    • Name: ADB#2 , Protocol: TCP , Host IP: 127.0.0.1 , Host Port: 5554 , Guest IP: 10.0.2.15 , Guest Port: 5554

USB settings

  • Enable USB Controller not checked

Current approach

The current approach is represented by all of the current settings that I have made which still lead to a randomly appearing emulator-5554 .

Using adb kill-server & adb -s emulator-5554 emu kill didn't have any effect aswell.

Question

Is there anything I can do to stop emulator-5554 from starting up and therefore showing up in my adb devices ?

I could solve the problem by using the following port forwarding rules.

  • Only adapter 1 is active, adapter 2-4 are not enabled
  • Attatched to: NAT
  • Port forwarding :
    • Name: ADB#1 , Protocol: TCP , Host IP: leave blank, Host Port: 55551 , Guest IP: leave blank, Guest Port: 5555
    • Name: ADB#2 , Protocol: TCP , Host IP: leave blank, Host Port: 55541 , Guest IP: leave blank, Guest Port: 5554

So the difference to my first approach is leaving blank both host and guest IP as well as choosing different ports for host and guest ports.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM