Connecting to Android emulator via local IP when IP is in 10.xxx range

I have a web server running on my computer. I am developing an Android application that is being tested on an AVD emulator. The emulator uses the IP address 10.0.2.2 to access the localhost on the hosting. This way everything works well.

However, what I would like to do is install Wireshark on my PC and capture the network traffic between the Android app and the web server on my PC.

This cannot be done when using 10.0.2.2, you need to use the IP address of your web server (the web server is only local, it does not have a public IP address).

The problem is that on our network all computers have a local address from the 10.xxx range So when trying to connect to my PC's local IP address which is 10.abc the connection fails because the emulator is also using the same address space.

What would be the easiest way to solve this problem?

Changing the local IP address of my PC is not an option.

Edit: I found a way to change the subnet used by the emulator. I found out that Android uses quemu. After reading this , I started the emulator from the command line with this command:

emulator @Nexus_5X_API_25 -qemu -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9

      

Eumlator starts, but I get the following warning: warning: netdev mynet0 is not equal

And when I check the IP address of the Android device using adb shell, I see that the IP address of the device is still 10.0.2.15, so it still uses the 10.0.2.x address space and not 192.168.xx as I expected.

I found this note in the quemu documentation, but could not find any other parameters that need to be added to the command: Note - if you specify any networking options on the command line (via -net or -netdev) then QEMU will require you to provide options sufficient to define and connect up both parts. (Forgetting to specify the backend or the network device will give a warning message such as "Warning: netdev mynet0 has no peer", "Warning: vlan 0 is not connected to host network" or "Warning: vlan 0 with no nics"; the VM will then boot but will not have functioning networking.)

EDIT2: I changed the command to look like this and now there is no warning:@Nexus_5X_API_25 -debug init -qemu -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9 -device virtio-net-pci,netdev=mynet0

However, it still doesn't work and that's beacause. emulator.exe cannot override the netdev qemu command and instead adds it to the end, so the network settings remain unchanged.

Below is a list of QEMU options:

emulator: argv[00] = "C:\Users\nikola\AppData\Local\Android\sdk\emulator/qemu/windows-x86_64/qemu-system-i386.exe"
emulator: argv[01] = "-dns-server"
emulator: argv[02] = "xx.xx.xx.xx,xx.xx.xx.xx,xx.xx.xx.xx,xx.xx.xx.xx"
emulator: argv[03] = "-serial"
emulator: argv[04] = "null"
emulator: argv[05] = "-cpu"
emulator: argv[06] = "android32"
emulator: argv[07] = "-enable-hax"
emulator: argv[08] = "-smp"
emulator: argv[09] = "cores=2"
emulator: argv[10] = "-m"
emulator: argv[11] = "1536"
emulator: argv[12] = "-lcd-density"
emulator: argv[13] = "420"
emulator: argv[14] = "-kernel"
emulator: argv[15] = "C:\Users\xxx\AppData\Local\Android\sdk/system-images\android-25\google_apis\x86\/kernel-ranchu"
emulator: argv[16] = "-initrd"
emulator: argv[17] = "C:\Users\xxx\AppData\Local\Android\sdk/system-images\android-25\google_apis\x86\/ramdisk.img"
emulator: argv[18] = "-object"
emulator: argv[19] = "iothread,id=disk-iothread"
emulator: argv[20] = "-drive"
emulator: argv[21] = "if=none,overlap-check=none,cache=unsafe,index=0,id=system,file=C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd\system.img.qcow2,read-only"
emulator: argv[22] = "-device"
emulator: argv[23] = "virtio-blk-pci,drive=system,iothread=disk-iothread,modern-pio-notify"
emulator: argv[24] = "-drive"
emulator: argv[25] = "if=none,overlap-check=none,cache=unsafe,index=1,id=cache,file=C:\Users\nikola\.android\avd\Nexus_5X_API_25.avd/cache.img.qcow2,l2-cache-size=1048576"
emulator: argv[26] = "-device"
emulator: argv[27] = "virtio-blk-pci,drive=cache,iothread=disk-iothread,modern-pio-notify"
emulator: argv[28] = "-drive"
emulator: argv[29] = "if=none,overlap-check=none,cache=unsafe,index=2,id=userdata,file=C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd/userdata-qemu.img.qcow2,l2-cache-size=1048576"
emulator: argv[30] = "-device"
emulator: argv[31] = "virtio-blk-pci,drive=userdata,iothread=disk-iothread,modern-pio-notify"
emulator: argv[32] = "-drive"
emulator: argv[33] = "if=none,overlap-check=none,cache=unsafe,index=3,id=sdcard,file=C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd/sdcard.img.qcow2,l2-cache-size=1048576"
emulator: argv[34] = "-device"
emulator: argv[35] = "virtio-blk-pci,drive=sdcard,iothread=disk-iothread,modern-pio-notify"
emulator: argv[36] = "-netdev"
emulator: argv[37] = "user,id=mynet"
emulator: argv[38] = "-device"
emulator: argv[39] = "virtio-net-pci,netdev=mynet"
emulator: argv[40] = "-netdev"
emulator: argv[41] = "user,id=mynet2,net=10.0.3.0/24"
emulator: argv[42] = "-device"
emulator: argv[43] = "virtio-net-pci,netdev=mynet2"
emulator: argv[44] = "-show-cursor"
emulator: argv[45] = "-L"
emulator: argv[46] = "C:\Users\xxx\AppData\Local\Android\sdk\emulator/lib/pc-bios"
emulator: argv[47] = "-soundhw"
emulator: argv[48] = "hda"
emulator: argv[49] = "-vga"
emulator: argv[50] = "none"
emulator: argv[51] = "-netdev"
emulator: argv[52] = "user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9"
emulator: argv[53] = "-device"
emulator: argv[54] = "virtio-net-pci,netdev=mynet0"
emulator: argv[55] = "-append"
emulator: argv[56] = "qemu=1 androidboot.hardware=ranchu clocksource=pit android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=1 ndns=4"
emulator: argv[57] = "-android-hw"
emulator: argv[58] = "C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd/hardware-qemu.ini"

      

I have replaced all confidential data xxx

+3


source to share





All Articles