Flutter Android (Xiaomi/MIUI): SocketException Failed host lookup for .local mDNS hostname


I’m building a Flutter app that discovers a local device over Wi-Fi and calls its local REST API.

On Xiaomi/Redmi (MIUI), local mode fails with DNS resolution for .local hostnames, while the same flow works on other Android devices.

I can make it work using direct IP, but I want to use hostname because IP may change (DHCP/network changes).

Error log:


[RESPONSE] [REST REQUEST] ************* ERROR *************
           {
             "method": "GET",
             "url": "https://type-macaddres.local/...",
             "stage": "connection",
             "error": "SocketException: Failed host lookup: 'type-macaddres.local' (OS Error: No address associated with hostname, errno = 7)",
             "mappedError": {
               "url": "https://type-macaddres.local/...",
               "statusCode": 503,
               "description": "Failed host lookup: 'type-macaddres.local'",
               "type": "ConnectionError",
               "errors": {
                 "code": 503,
                 "message": "Failed host lookup: 'type-macaddres.local'"
               }
             }
           }
           *********************************

What I’m using in Flutter:

  • nsd package for service discovery (DNS-SD/mDNS), service type like _name_secondaname._tcp

  • dart:io HttpClient for REST requests

  • connectivity_plus for connection state

  • Discovery with autoResolve: true and ipLookupType: IpLookupType.any

Example discovery call:

final discovery = await startDiscovery(
  '_name_secondaname._tcp.',
  autoResolve: true,
  ipLookupType: IpLookupType.any,
);

Context:

  • Flutter app (Android)

  • Request to http(s)://<device-name>.local/...

  • Fails only on Xiaomi/Redmi (MIUI)

Already checked:

  • Android permissions: INTERNET, ACCESS_NETWORK_STATE, CHANGE_WIFI_MULTICAST_STATE

  • Private DNS on/off

  • MIUI battery/data restrictions disabled

  • ipLookupType: any

Questions:

  1. Is this a known MIUI limitation with resolving .local hostnames from Flutter/Dart HttpClient?

  2. Is using direct IP the only reliable approach on Xiaomi?

  3. Any Xiaomi-specific workaround that reliably fixes mDNS hostname resolution?

NOTE: I've all the manifest permissions, and have done everything that could find, wich not worked. NOTE #2: I'm testing with real device (Xiaomi Redmi 8T)

2
May 11 at 11:42 AM
User AvatarReborned BBIAJ
#android#flutter#dns#iot#xiaomi

No answer found for this question yet.