I am trying to configure a Android x86 running machine using Oracle VirtualBox so that it works with Eclipse. I am having some trouble in making my virtual machine "online". I connected the phone to adb by typing the following in the Android Terminal Emulator:
ifconfig eth0 192.168.40.1 netmask 255.255.255.0
route add default gw 192.168.40.1 dev eth0
Afterwards, I switched to cmd and typed adb connect localhost
But when I try to run my test code using Eclipse on the virtual Android, it does not appear in the Android Device Chooser Menu. Furthermore, when I typed adb devices
in cmd, this was the response:
List of devices attached
localhost:5555 offline
The other thing that worries me is that each time after I shut down the VM, I have to type the ifconfig
and route add
commands again in the terminal when I restart, in order to connect to the device.
What can I do to make the device online?
EDIT: In case it matters, the VM is configured to communicate over a NAT Network. This is what my Port Forwarding Rules look like: Protocol: TCP
Host IP: *
Host Port: 5555
Guest IP: *
Guest Port: 5555
EDIT2 Related Question: Error: device offline
EDIT3: Potential Solution: Android device chooser - My device seems offline
I reckon most people have already tried this, but in my case the issue was fixed simply by connecting to VirtualBox's built-in wifi access point called "VirtWifi" (which gives the virtual machine internet access). All my virtual machine network changes are default besides the 5555 Port Forwarding rule. I am virtualizing Android v9.0 (Pie).
This is much easier than all of that, to enable adb over tcpip in the Android VM Terminal Emulator type:
Then to connect via adb from a command line on your Eclipse machine:
The VM should now be available via adb devices as well as via the device view in Eclipse.
Just configure the vm to use the pridge network mode and have a dhcp server enabled on the network.
When I've started to develop some Android application, I have to deal with the same problem, so looking for something, on the
VirtualBox guide
I've read that the NAT does not require any configuration on the host network and guest system and for this reason, it is the default networking mode in VirtualBox. A virtual machine with NAT enabled acts much like a real computer that connects to the Internet through a router. The "router", in this case, is the VirtualBox networking engine, which maps trac from and to the virtual machine transparently. In VirtualBox this router is placed between each virtual machine and the host. This separation maximizes security since by default virtual machines cannot talk to each other. The disadvantage of NAT mode is that, much like a private network behind a router, the virtual machine is invisible and unreachable from the outside internet. The network frames sent out by the guest operating system are received by VirtualBox's NAT engine, which extracts the TCP/IP data and resends it using the host operating system. To an application on the host, or to another computer on the same network as the host, it looks like the data was sent by the VirtualBox application on the host, using an IP address belonging to the host. VirtualBox listens for replies to the packages sent, and repacks and resends them to the guest machine on its private network.The virtual machine receives its network address and configuration on the private network from a DHCP server integrated into VirtualBox. The IP address thus assigned to the virtual machine is usually on a completely different network than the host. As the virtual machine is connected to a private network internal to Virtual-Box and invisible to the host, network services on the guest are not accessible to the host machine or to other computers on the same network. However, like a physical router, VirtualBox can make selected services available to the world outside the guest through port forwarding. This means that VirtualBox listens to certain ports on the host and resends all packets which arrive there to the guest, on the same or a different port. So, executing
cmd
, go to the folder where the VirtualBox is installed and where the VBManage.exe is and type this in order to apply the TPC port forwarding:Now you can connect to your virtual machine through adb with: