# Willing to pay: err\_connection\_refused android

**URL:** <https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711>\
**Category:** Capacitor\
**Created:** [March 24, 2022, 1:58pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711 "2022-03-24T13:58:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharrington0](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tharrington0/32/141136_2.png) [@tharrington0](https://forum.ionicframework.com/u/tharrington0)\
**Post date:** [March 24, 2022, 1:58pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/1 "2022-03-24T13:58:29Z")

</div>

I am using the cordova in-app-browser plugin to oauth into salesforce. This used to work fine for both android and iOS but it seems to be broken now that I have updated capacitor and android to API 31 I am getting a variety of errors depending on my configuration. The original error was net::ERR\_CLEARTEXT\_NOT\_PERMITTED

Which was solved by adding cleartext: true to my capacitor.config.ts file. But now I am getting ERR\_CONNECTION\_REFUSED.

Here is my capacitor.config.ts:

```auto
import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'org.myapp.app',
  appName: 'MyApp',
  webDir: 'www',
  bundledWebRuntime: false,
  server: {
    // url: 'http://localhost',
    cleartext: true,
    hostname: '127.0.0.1'
  }
};

export default config;

```

Here is my ionic info:

```auto
Ionic:

   Ionic CLI : 6.19.0 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework : @ionic/angular 6.0.9
   @angular-devkit/build-angular : 13.0.4
   @angular-devkit/schematics : 13.0.4
   @angular/cli : 13.0.4
   @ionic/angular-toolkit : 5.0.3

Capacitor:

   Capacitor CLI : 3.4.1
   @capacitor/android : 3.4.3
   @capacitor/core : 3.4.1
   @capacitor/ios : 3.4.1

Utility:

   cordova-res : 0.15.4
   native-run : 1.5.0

System:

   NodeJS : v16.13.2 (/usr/local/bin/node)
   npm : 8.1.2
   OS : macOS Monterey

```

And finally the code that creates the browser:

```auto
const clientId = this.myDataService.getAppId();
    const redirectUri = 'http://localhost/callback';
    const loginUrl = 'https://mysforg.force.com/services/oauth2/authorize?display=touch' +
          '&response_type=token&client_id=' + clientId +
          '&redirect_uri=' + redirectUri;
    console.log('### loading login url: ' + loginUrl);
    const options = 'location=no,toolbarposition=top,enableViewportScale=yes,closebuttoncaption=Cancel,' +
      'clearsessioncache=yes,clearcache=yes';
    console.log('### loginUrl: ' + loginUrl);
    const browser = this.iab.create(loginUrl, '_blank', options);

    console.log('### loaded');
    browser.on('loadstart').subscribe(
      (event) => {
        console.log('### got uri: ' + redirectUri);
        // if(event.url.substr(0, redirectUri.length) === redirectUri) {
        // this.handleLoginEvent(event.url, browser);
        // }
      }, err => {
        console.log('### got an error: ', err);
      }
    );

```

---

<div class="post-metadata">

**Author:** ![thomasvidas](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/thomasvidas/32/137760_2.png) [@thomasvidas](https://forum.ionicframework.com/u/thomasvidas)\
**Post date:** [March 25, 2022, 5:27pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/2 "2022-03-25T17:27:20Z")

</div>

It looks like you’re running both the Android emulator and your API on the same network, correct? Android emulator’s `localhost` is the _emulator’s_ `localhost`, not your computer. This is unlike the iOS simulator where `localhost` on the sim is `localhost` for your computer.

In your Capacitor code, to reach your local API, try replacing `http://localhost/callback` with `http://10.0.2.2/callback`. On the default Android emulator, `10.0.2.2` will forward requests to your computer’s `localhost`.

For more info, check out the [Android emulator networking guide](https://developer.android.com/studio/run/emulator-networking) and [this StackOverflow post](https://stackoverflow.com/questions/5528850/how-do-you-connect-localhost-in-the-android-emulator).

I only accept thanks and high fives as payment! 😄

---

<div class="post-metadata">

**Author:** ![tharrington0](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tharrington0/32/141136_2.png) [@tharrington0](https://forum.ionicframework.com/u/tharrington0)\
**Post date:** [March 30, 2022, 8:53pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/3 "2022-03-30T20:53:02Z")

</div>

> [@thomasvidas](#):
>
> It looks like you’re running both the Android emulator and your API on the same network, correct? Android emulator’s `localhost` is the _emulator’s_ `localhost` , not your computer. This is unlike the iOS simulator where `localhost` on the sim is `localhost` for your computer.

No, I am not running it on the same network. The way it works is there is a login website that is opened in in app browser. This is not being run locally, it is on the [Salesforce.com](http://Salesforce.com) platform. When the user enters their credentials within salesforce, the in app browser parses out the token and then they are authenticated in the app. But the callback here does not open. In the past, I had used the cordova whitelist plugin.

---

<div class="post-metadata">

**Author:** ![thomasvidas](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/thomasvidas/32/137760_2.png) [@thomasvidas](https://forum.ionicframework.com/u/thomasvidas)\
**Post date:** [March 31, 2022, 9:35pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/4 "2022-03-31T21:35:09Z")

</div>

What is the URL for the `ERR_CONNECTION_REFUSED`? Is it for `force.com` or for `127.0.0.1`? The Salesforce URL is using https which wouldn’t have triggered the `ERR_CLEARTEXT_NOT_PERMITTED` error; which led me to believe that your error was happening during callback, due to the localhost issue. My mistake!

---

<div class="post-metadata">

**Author:** ![tharrington0](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tharrington0/32/141136_2.png) [@tharrington0](https://forum.ionicframework.com/u/tharrington0)\
**Post date:** [April 1, 2022, 5:41pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/5 "2022-04-01T17:41:07Z")

</div>

Do you have any other thoughts? Please let me know if you’re willing to do a phone call!

---

<div class="post-metadata">

**Author:** ![tharrington0](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tharrington0/32/141136_2.png) [@tharrington0](https://forum.ionicframework.com/u/tharrington0)\
**Post date:** [April 7, 2022, 4:45am UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/6 "2022-04-07T04:45:05Z")

</div>

The connection refused is the localhost connection, IE the redirect URI

 ![Screen Shot 2022-04-07 at 12.44.05 AM](https://global.discourse-cdn.com/ionicframework/original/3X/6/4/64f30e3fd16d7ad31f82aaf2ffbea059f9eccdf4.jpeg)

I have attached a screenshot showing this issue.

---

<div class="post-metadata">

**Author:** ![tharrington0](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tharrington0/32/141136_2.png) [@tharrington0](https://forum.ionicframework.com/u/tharrington0)\
**Post date:** [April 7, 2022, 1:48pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/7 "2022-04-07T13:48:46Z")

</div>

@thomasvidas If you go here and scroll down, you will see people facing a similiar issue as well:

> <https://github.com/ionic-team/capacitor/issues/2391>
>
> \# Bug Report
> 
> \## Capacitor Version
> 
> 
> \`npx cap doctor\` output:
> 
> 💊 Capaci…tor Doctor 💊 
> 
> Latest Dependencies:
> 
> @capacitor/cli: 1.4.0
> 
> @capacitor/core: 1.4.0
> 
> @capacitor/android: 1.4.0
> 
> @capacitor/ios: 1.4.0
> 
> Installed Dependencies:
> 
> @capacitor/cli 1.4.0
> 
> @capacitor/android 1.4.0
> 
> @capacitor/core 1.4.0
> 
> @capacitor/ios 1.4.0
> 
> 
> \[error\] Main Acitivity ".MainActivity" is not in manifest package "com.bubblevr.wedo". Please update the packages to be the same.
> \## Affected Platform(s)
> 
> 
> \- \[\] Android
> \- \[\] iOS
> \- \[\] Electron
> \- \[\] Web
> 
> \## Current Behavior
> 
> 
> In order to fix some access issue (XHR call to these domains would be cancelled on iOS without it) I am setting the following json in capacitor.config.json
> 
> \`
> "server": {
> "allowNavigation": \[
> "localhost",
> "ec2-35-181-50-61.eu-west-3.compute.amazonaws.com:1337",
> "ec2-15-188-204-14.eu-west-3.compute.amazonaws.com:1337",
> "wedo-front-1670696535.eu-west-3.elb.amazonaws.com"
> \]
> }
> \`
> 
> But as soon as I set these, I get an error page on load of the app on android "the webpage at http://localhost/ could not be loaded because : net::ERR\_CONNECTION\_REFUSED.
> \<img width="378" alt="Screenshot 2020-01-30 at 14 22 44" src="https://user-images.githubusercontent.com/4233878/73453599-ab701600-436c-11ea-8b83-39ad126a2e76.png"\>
> 
> I have also tried adding "\*" in the listed of allowed origins, but I cannot get it to work.
> Removing the "allowNavigation" array will let my app load properly.
> 
> \## Expected Behavior
> Application load should not be blocked.
> 
> \## Other Technical Details
> 
> 
> 
> \`npm --version\` output:
> 6.4.1
> \`node --version\` output:
> v11.0.0
> 
> \`pod --version\` output (iOS issues only):
> 
> \## Other Information

---

<div class="post-metadata">

**Author:** ![dvtopiya](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@dvtopiya](https://forum.ionicframework.com/u/dvtopiya)\
**Post date:** [June 10, 2022, 11:26am UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/8 "2022-06-10T11:26:44Z")

</div>

@tharrington0 I am facing the same issue. Can you please let me know whether you got any solution yet?

---

<div class="post-metadata">

**Author:** ![michaelkariv](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@michaelkariv](https://forum.ionicframework.com/u/michaelkariv)\
**Post date:** [November 4, 2022, 3:48pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/9 "2022-11-04T15:48:24Z")

</div>

Same here. I have created a minimalistic Angular 14 app. I use Capacitor, Android only, Trapeze for configuration. Trapeze allows me to wipe the android folder and rebuild it from scratch each time I make a change.

I have placed this into a public repository. I’d be grateful if anyone could try it and see if it works for you, or tell me what I am doing wrong. I incorporated all the advice I found on the StackOverflow, to no good result

The repo: [Remote Debugging of Angular 14 + Capacitor 4 Hybrid App on Android - Fails Remote Debugging - Source Maps access](https://github.com/michaelkariv/angular-capacitor-trapeze-sourcemap)

---

<div class="post-metadata">

**Author:** ![Jean-PierreScholtz](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@Jean-PierreScholtz](https://forum.ionicframework.com/u/Jean-PierreScholtz)\
**Post date:** [January 6, 2023, 10:38am UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/10 "2023-01-06T10:38:42Z")

</div>

Any update on this error? I had been testing an Ionic App just fine an hour ago. Got the cleartext error 👍resolved, then got hit with the connection refused?

---

<div class="post-metadata">

**Author:** ![mani0011](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@mani0011](https://forum.ionicframework.com/u/mani0011)\
**Post date:** [January 9, 2023, 12:36pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/11 "2023-01-09T12:36:51Z")

</div>

In your AndroidManifest.xml add

```auto
cleartextTrafficPermitted="true"

```

in your application tag.

---

<div class="post-metadata">

**Author:** ![Johanson](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@Johanson](https://forum.ionicframework.com/u/Johanson)\
**Post date:** [February 1, 2023, 10:41pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/12 "2023-02-01T22:41:26Z")

</div>

Did you mean to say to add android:usesCleartextTraffic=“true”? Because there is no such attribute named android:cleartextTrafficPermitted (not sure where you got that from).

In any case, it still doesn’t work. Same error.

This project has worked for years. Now suddenly completely broken. No idea how to fix it.

---

<div class="post-metadata">

**Author:** ![mvaljento0](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mvaljento0/32/143903_2.png) [@mvaljento0](https://forum.ionicframework.com/u/mvaljento0)\
**Post date:** [February 7, 2023, 3:18pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/13 "2023-02-07T15:18:12Z")

</div>

Have you tried running with --external argument?

For example I’m running in emulator with the following command:

ionic cap run android --external --livereload --port=8010 --target=Pixel\_4\_API\_Tiramisu

---

<div class="post-metadata">

**Author:** ![PURUSHOTHAM-REDDY-N](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@PURUSHOTHAM-REDDY-N](https://forum.ionicframework.com/u/PURUSHOTHAM-REDDY-N)\
**Post date:** [May 23, 2023, 4:51pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/14 "2023-05-23T16:51:14Z")

</div>

step-1 : Run the emulator before serving the project

Navigate to the Android SDK Tools directory: Use the `cd` command to navigate to the directory where the Android SDK tools are located. By default, it is usually located at `C:\Users\YourUsername\AppData\Local\Android\Sdk\emulator` . Replace `YourUsername` with your actual Windows username.

List available emulators: Run the following command to see a list of available emulators:  
command =\> emulator -list-avds

1. This command will display the names of the Android Virtual Devices (AVDs) that you have created.
2. Launch the emulator: To launch an emulator, use the following command, replacing `avd_name` with the name of the emulator you want to start:

command =\> emulator -avd avd\_name

step 2 : run the capacitor serve

use this command

ionic cap run android --external --livereload --port=8010 --target=Pixel\_4\_API\_33

you can use any target that you have

---

<div class="post-metadata">

**Author:** ![Sebex142](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@Sebex142](https://forum.ionicframework.com/u/Sebex142)\
**Post date:** [November 15, 2023, 1:16pm UTC](https://forum.ionicframework.com/t/willing-to-pay-err-connection-refused-android/221711/15 "2023-11-15T13:16:39Z")

</div>

Hello, I had the same problem, just remove `hostname` variable from `capacitor.config`, and use `url` instead with your external ipV4, for ex.:  
In Windows you can run `cmd`: then `ipconfig` and get this IP from the end of results: for ex.  
` IPv4 Address. . . . . . . . . . . : 192.168.1.26`
