Android x86 on VirtualBox: Android Connected But Not Online

南楼画角 提交于 2019-12-05 02:59:34

问题


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


回答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.




回答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



回答3:


Just configure the vm to use the pridge network mode and have a dhcp server enabled on the network.



来源:https://stackoverflow.com/questions/10760490/android-x86-on-virtualbox-android-connected-but-not-online

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!