There is a simple trick which allows your application to resolve a hostname to IP address defined by you even in cases when you do not have access to DNS server. This trick could be also used when you’re connected via VPN and the emulator is not able to resolve DNS record available only in private network.
Let’s add following hostname record which should be resolved by application on Android:
First of all, you need to start your AVD with parameter ‘-writable-system’, because emulator’s filesystem is by default read-only.
Let’s get names of available AVDs.
Example for macOS:
The output might look like:
Start the emulator:
You should see the following warning:
The emulator will start. Now you need to remount the filesystem so it will become writable. This could be done via adb tool which is in platform-tools directory.
Version for macOS:
Now you can start the shell and append the line with configuration to /etc/hosts:
Now you can test the configuration by ping: