Android x86 on VirtualBox: Android Connected But Not Online

12,463

Solution 1

This is much easier than all of that, to enable adb over tcpip in the Android VM Terminal Emulator type:

adb tcpip 5555

Then to connect via adb from a command line on your Eclipse machine:

adb connect 192.168.40.1:5555

The VM should now be available via adb devices as well as via the device view in Eclipse.

Solution 2

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:

VBoxManage modifyvm "NameOfYourAndroidVM" --natpf1 adb,tcp,*,5555,*,5555

Now you can connect to your virtual machine through adb with:

adb connect localhost
Share:
12,463

Related videos on Youtube

stephen
Author by

stephen

Updated on June 04, 2022

Comments

  • stephen
    stephen about 2 years

    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

  • Josh1billion
    Josh1billion almost 12 years
    Seems you need to remove the spaces in this part, otherwise VBoxManage spits out an error: adb, tcp, *, 5555, *, 5555
  • Ant4res
    Ant4res almost 12 years
    @Josh1billion Thanks! I had not noticed that I've misspelled the spaces! I edit my answer immediately!
  • Justin Buser
    Justin Buser almost 12 years
    Actually the spaces were spelled correctly, they were just not supposed to be there :)