2

I am trying to create a bridge between android emulator (from android sdk) and host system using -net-tap. Is there any working manual for that case? I have tried to launch emulator with -net-tap tap0 - tap0 appeared in host system, but no one interfaces appeared in guest android. I also tried -qemu -net tap,iface=tap1,script=no, but it also doesn't work. I checked /proc/kmsg, there are no anything connected with new interface.

Full cmdline looks like /opt/android-sdk/emulator -avd test-x86 -accel off -no-audio -net-tap tap0 -qemu -net tap,ifname=tap1,script=no

Does anyone have an idea?

1

I think -net tap is the old way, use -netdev tap with new android sdk emulator and -device virtio-net-pci for x86 android emulator. For ARM emulator you must use an other device.

And you must install the emulator package with the sdkmanager as this:

sdkmanager emulator

Then you can use the emulator located in /opt/android-sdk/emulator/emulator.

Create a network bridge which include a tap interface (tap0) for the emulator and an ethernet interface (enp0s20u1) connected to a lan network.

# ip addr flush dev enp0s20u1
# ip link set enp0s20u1 down
# ip tuntap add dev tap0 mode tap user $(whoami)
# ip link add br0 type bridge
# ip link set enp0s20u1 master br0
# ip link set tap0 master br0
# ip link set enp0s20u1 up
# ip link set tap0 up
# ip link set br0 up

A quick overview of the bridge.

# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.0050b609a5d1       no              enp0s20u1
                                                        tap0

Start a dhcp client on the bridge:

# dhcpcd br0

Then you can plug the tap interface (tap0) to the android emulator via -qemu options when you launch the emulator.

./opt/android-sdk/emulator/emulator \
  -avd android_25_x86 \
  -verbose -no-window \
  -qemu \
  -device virtio-net-pci,netdev=hn0,mac=52:55:00:d1:55:51 \
  -netdev tap,id=hn0,ifname=tap0,script=no,downscript=no

Normaly a new eth1 interface is present in the android emulator. And you can run the dhcpclient binary if it present or configure static route to your network, then it work.

generic_x86:/ # ping -c 1 -I eth1 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.1.60 eth1: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=17.1 ms

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 17.160/17.160/17.160/0.000 ms

But I have some issues to ping the emulator from the outside or route all the traffic in the emulator to the host network, see my other post.

Connect android emulator to lan

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.