proxyandroid-emulatorvirtual-machineinternet-connection

Android Virtual Device Emulator Cannot Connect to the Internet on VM


I am running an Android Virtual Device (AVD) Emulator from Android Studio (Iguana), which is running on my virtual machine (ubuntu). My host machine (also Ubuntu) is running a proxy. I have configured my Virtual Machine and it can connect to the internet for all senses and purposes. Android Studio on my VM can also connect to the internet to download packages. But when I launched my Android Virtual Device (Pixel XL API 30 x86), it cannot connect to the internet. How can I resolve the issue?


Solution

  • Previously, on my host machine (ubuntu), I ran ip addr to find out which ip address is being used by my host machine to communicate with the VM. The IP address was 192.xxx.xxx.1, which was available under virbr0.

    This address was used to configure my Virtual Machine to connect to the internet along with an available port (i.e., 3128 - commonly used by proxy servers). I added the following two lines in the /etc/environment file to apply a system-wide proxy:

    http_proxy="http://192.xxx.xxx.1:3128"
    https_proxy="http://192.xxx.xxx.1:3128"
    

    This had previously solved the internet connection issue in VM.

    I wanted to apply this same proxy to the emulated Android Virtual Device but I did not know how. As I mentioned in the question, I have tried to go to AVD's Settings > Proxy to setup the Proxy through "Manual Proxy Configuration" but it did not work.

    Turned out there was a simpler way: Go to Emulated Device's Wifi > AndroidWifi > Settings (click on the wheel sign) > Edit (click on the Pen sign on the top right) > Andvanced Setting (Clicking on the Down arrow on the right will uncollapse a hidden menu) > Proxy >

    1. Set Proxy Hostname as 192.xxx.xxx.1;
    2. Set Proxy Port as 3128

    -> Press Save Button.

    Voila!! The emulator can now connect to the internet.