Skip to content

Flutter errorFlutter: “SocketException: Failed host lookup: 'api.example.com' (OS Error: No address associated with hostname, errno = 7)”

An HTTP call fails with SocketException: Failed host lookup. The device couldn’t turn the domain name into an address, so no request was sent. Often the app works in debug and fails only in the release build or on a real phone, which points at a missing network permission rather than at the server.

Short answer

If it fails only in release on Android, add <uses-permission android:name="android.permission.INTERNET" /> to android/app/src/main/AndroidManifest.xml: Flutter’s debug manifest has it, the main one doesn’t. On macOS, add com.apple.security.network.client to both entitlements files. Otherwise check the host name, the device’s internet and DNS (try the URL in the device’s browser), and catch SocketException to show an offline message.

Why the lookup failed, and the fix

  1. 01

    No INTERNET permission in the release manifest

    “Android apps must declare their use of the internet in the Android manifest” Flutter, Networking

    A new Flutter project adds the INTERNET permission only to the debug and profile manifests, so a release build or a Play Store install has no network. Add it to the main manifest, outside the application tag, then stop the app and run it again: hot reload and hot restart don’t pick up manifest changes.

    <!-- android/app/src/main/AndroidManifest.xml -->
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
      <uses-permission android:name="android.permission.INTERNET" />
      <application ...>
  2. 02

    A macOS app without the network entitlement

    “macOS apps must allow network access in the relevant *.entitlements files.” Flutter, Networking

    macOS apps are sandboxed. Add the network client key to macos/Runner/DebugProfile.entitlements and Release.entitlements; the debug file alone makes it fail only in release. Rebuild the app after the change.

    <key>com.apple.security.network.client</key>
    <true/>
  3. 03

    The emulator or device has no working DNS

    An Android emulator that lost its network after the computer changed Wi-Fi or VPN can’t resolve any name. Open a website in the emulator’s browser. If it fails too, cold boot the emulator, start it with a public DNS server (emulator -avd NAME -dns-server 8.8.8.8), or wipe its data; on a phone, switch networks or turn off a VPN or Private DNS setting that blocks the host.

  4. 04

    A wrong host name, or an app that assumes it is online

    “Exception thrown when a socket operation fails.” Dart, SocketException class

    A typo in the host name, or a base URL built from the wrong environment variable, fails the lookup. (An empty URL or http://localhost gives a different error; see the FAQ.) Log the full URL before the request. Real users go offline too, so catch SocketException and show a retry message instead of a crash.

    try {
      final res = await http.get(Uri.parse('$baseUrl/orders'));
    } on SocketException catch (e) {
      // e.message: Failed host lookup
      showOfflineBanner();
    }

Checked against the vendor’s docs on : Flutter: Networking (Android permission, macOS entitlement); Android Developers: Connect to the network (INTERNET permission); Dart API: SocketException class.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Flutter HandshakeException CERTIFICATE_VERIFY_FAILED · Android cleartext HTTP blocked · Flutter web “XMLHttpRequest error” · Flutter “version solving failed”

Questions

More on this error

Do I need to ask the user for the INTERNET permission?

No. It is a normal permission, granted at install time with no prompt. It only has to be in the manifest.

It says Connection refused instead. Is that the same?

No. Connection refused means the name resolved but nothing answered on that port, often localhost on an emulator, where the computer is 10.0.2.2. Failed host lookup means the name itself couldn’t be resolved.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.