question

TonyNicholls-1752 avatar image
0 Votes"
TonyNicholls-1752 asked YonglunLiu-MSFT answered

MAUI Android Emulator networking exception - can't resolve hostname

So I have a MAUI application that I'm trying to debug using an Android Pixel 5 emulator.

It contains a call to an external URL (https://ts-restapi-dev.greatideaz.com) that it claims that it can't resolve to its IP address (20.116.90.125)

I run the same code in Windows and it works. Run the same code on a physical Android device and it works....

Just fails on the android emulator :(

Any ideas - I'm assuming that the emulator networking isn't correctly set up but I have the latest 17.3 preview with the latest version of the emulators.

dotnet-maui
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I've tried to call the external URL (https://ts-restapi-dev.greatideaz.com), however, it always returns the 404 not found error both on Android and Windows.

For further investigation, could you please provide more detailed information, such as a minimal sample or how did you call the external URL?

I run the same code in Windows and it works. Run the same code on a physical Android device and it works....

Please check the internet connection of your Android Emulator, you could use the following code:

private bool isNetworkConnected()
{
    ConnectivityManager cm = Android.App.Application.Context.GetSystemService(Context.ConnectivityService) as ConnectivityManager;
    return cm.GetNetworkCapabilities != null;
}

If the function returns false, you could try to change DNS on Android emulator or create new one for test.

0 Votes 0 ·

The network connection is ok.

The issue seems to be DNS related. If I add an entry to my laptop's hosts file then everything works.

So the question is how does the emulator figure out DNS - is there something I need to setup there?

0 Votes 0 ·

1 Answer

YonglunLiu-MSFT avatar image
0 Votes"
YonglunLiu-MSFT answered

Hello,

So the question is how does the emulator figure out DNS - is there something I need to setup there?

Referring to this official documentation Configuring the emulator DNS settings, you could find the recommended way to configure the emulator DNS settings is the following content:

When starting the emulator at the command line, you can also use the -dns-server <serverList> option to manually specify the addresses of DNS servers to use, where <serverList> is a comma-separated list of server names or IP addresses. You might find this option useful if you encounter DNS resolution problems in the emulated network (for example, an "Unknown Host error" message that appears when using the web browser).

Due to you have resolved your issue by adding an entry to your laptop's hosts file, you could choose not to manually set up dns.

Best Regards,

Alec Liu.



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.