9

My development machine is simultaneously connected to two different networks. One is through ethernet (eth0), and the other is WiFi (en1). In this situation, the Android emulator appears to always want to reach out to the network on eth0. When starting the emulator from the command line, is there an option where I can tell it to use a specific network interface on the development machine (en1 in my case)?

It seems like this should be possible through args you can pass to the -qemu flag. However, the current version of the emulator will not start when you use this flag.

Eric Levine
  • 13,536
  • 5
  • 49
  • 49
  • I needed to do this because I needed the host to be behind my corporate firewall and the emulator to be in front. My hack involved running the emulator a VirtualBox VM and and binding the VM to the desired interface. Less than ideal, but got the job done. – Tymcode Oct 10 '18 at 23:32

2 Answers2

7

If you are only communicating with a specific address or subnet you can set up an apropriate route on the host machine by using the route add command. The syntax differs slightly for Windows and Linux:

Linux

route add -net target-ip netmask 255.255.255.0 metric 1 gw en1

Windows

route add target-ip mask 255.255.255.0 en1-gw-address metric 1 -p

You might want to adjust the netmask value (255.255.255.0) to your needs.

mattlaabs
  • 486
  • 3
  • 14
  • I'm looking for a way to route all HTTP requests, to any possible address, from the Android emulator to en1. – Eric Levine Sep 03 '11 at 18:26
  • Then you could use a free web proxy. Configure the emulator to use the proxy with the _http-proxy_ option and configure a route via en1 for the proxy's ip. – mattlaabs Sep 03 '11 at 22:03
  • Thats a good idea. Can you suggest a proxy that would be easy to setup? – Eric Levine Sep 05 '11 at 15:07
  • Try any from http://androidproxy.in/ . For setting up the proxy see also http://stackoverflow.com/questions/28380/proxy-with-android-emulator. – mattlaabs Sep 05 '11 at 19:09
  • Just to make sure I understand, you're saying to do "route add" and use one of those android.in proxies as the target ip. Then, set the emulator's http-proxy to that same target-ip. Is that correct? – Eric Levine Sep 05 '11 at 19:25
  • Exactly, this way all http traffic from the android emulator should be directed to the proxy and the traffic to the proxy will go through en1 as configured in the routing table. – mattlaabs Sep 05 '11 at 21:38
1

IMHO this is not possible since the emulator uses a virtual router rather than a physical network interface of your development PC

Have a closer look at this link - there is some detailed information about that
http://developer.android.com/guide/developing/devices/emulator.html#emulatornetworking

DonGru
  • 13,532
  • 8
  • 45
  • 55
  • 1
    So how does that virtual router decide which network interface to use on your development machine? To put it another way, When you start the emulator you can specify a proxy with the -http-proxy switch. I don't see a similar option to choose a network interface, but would expect that to exist. – Eric Levine Aug 29 '11 at 16:46
  • I'm not quite sure but I guess this has something to do with the way routing is defined at the PC – DonGru Aug 30 '11 at 12:13
  • It seems like this should be possible through args you can pass to the -qemu flag. However, the current version of the emulator will not start when you use this flag. – Eric Levine Sep 05 '11 at 15:27