# Capacitor Android app showing ERR\_CONNECTION\_REFUSED when using webDir: "dist"

**URL:** <https://forum.ionicframework.com/t/capacitor-android-app-showing-err-connection-refused-when-using-webdir-dist/250833>\
**Category:** Ionic React\
**Created:** [March 16, 2026, 6:03pm UTC](https://forum.ionicframework.com/t/capacitor-android-app-showing-err-connection-refused-when-using-webdir-dist/250833 "2026-03-16T18:03:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AtuI-Yadav](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@AtuI-Yadav](https://forum.ionicframework.com/u/AtuI-Yadav)\
**Post date:** [March 16, 2026, 6:03pm UTC](https://forum.ionicframework.com/t/capacitor-android-app-showing-err-connection-refused-when-using-webdir-dist/250833/1 "2026-03-16T18:03:41Z")

</div>

Hi everyone,

I’m building a mobile app using **React + Vite + Capacitor**. I am using the **dist build approach** instead of running a development server.

My `capacitor.config.ts` looks like this:

```auto
const config: CapacitorConfig = {
  appId: "co.testapp.com",
  appName: "Test App",
  webDir: "dist"
};

```

I build the project using:

```auto
npm run build
npx cap sync
npx cap run android

```

The `dist` folder is generated correctly and contains `index.html` and assets.

However, when the Android app starts, the WebView shows this error:

```auto
Failed to load resource: net::ERR_CONNECTION_REFUSED
Webpage https://localhost could not be loaded

```

It looks like Capacitor is still trying to load from `https://localhost` instead of the bundled files.

Things I have already checked:

- Removed any `server.url` from `capacitor.config.ts`

- Rebuilt the project (`npm run build`)

- Ran `npx cap sync`

- Cleaned the Android build (`./gradlew clean`)

- Confirmed that `dist/index.html` exists

Expected behavior:  
The app should load from `capacitor://localhost/index.html`.

Has anyone experienced this issue or knows what might cause Capacitor to still attempt loading `https://localhost`?

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![twestrick](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/twestrick/32/136131_2.png) [@twestrick](https://forum.ionicframework.com/u/twestrick)\
**Post date:** [March 16, 2026, 8:01pm UTC](https://forum.ionicframework.com/t/capacitor-android-app-showing-err-connection-refused-when-using-webdir-dist/250833/2 "2026-03-16T20:01:36Z")

</div>

To clarify something, the default Capacitor URL on Android is `https://localhost`. `capacitor://localhost` is only the default for iOS.

If you just run:

```auto
npm run build
npx cap sync

```

you do have files in `android/app/src/main/assets/public` including an `index.html` file? That is where your compiled JS assets get copied when running `cap sync`.

---

<div class="post-metadata">

**Author:** ![AtuI-Yadav](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@AtuI-Yadav](https://forum.ionicframework.com/u/AtuI-Yadav)\
**Post date:** [March 17, 2026, 6:59am UTC](https://forum.ionicframework.com/t/capacitor-android-app-showing-err-connection-refused-when-using-webdir-dist/250833/3 "2026-03-17T06:59:07Z")

</div>

> [@twestrick](#):
>
> you do have files in `android/app/src/main/assets/public` including an `index.html` file? That is where your compiled JS assets get copied when running `cap sync`.

Hello  
Yes index.html is there but still is not working

 ![image](https://global.discourse-cdn.com/ionicframework/original/3X/8/5/85cde105cd5ef1d51827c43477a723b7e8546686.png)

---

<div class="post-metadata">

**Author:** ![ptmkenny](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@ptmkenny](https://forum.ionicframework.com/u/ptmkenny)\
**Post date:** [March 19, 2026, 12:27pm UTC](https://forum.ionicframework.com/t/capacitor-android-app-showing-err-connection-refused-when-using-webdir-dist/250833/4 "2026-03-19T12:27:20Z")

</div>

How are you testing this, in an actual device or in the simulator?
