ionic-cli: Application Error - The connection to the server was unsuccessful

Description: When trying to launch emulator with Ionic 4 project, I am getting errors. I am running command in VS Code bash command line: ionic cordova emulate android --livereload --verbose I am getting the following error last time - [cordova] Command finished with error code 0: C:\Users\Gary\AppData\Local\Android\Sdk\platform-tools\adb.exe -s,emulator-5554,shell,am,start,-W,-a,android.intent.action.MAIN,-nio.ionic.starter/.MainActivity

Steps to Reproduce:

  1. Download My Github repo: https://github.com/gchan82/heartstoneLibApp
  2. run npm install +/-3. launch android studio emulator (Nexus 6, API 28 or Pixel 2, API 23)
  3. run: ionic cordova emulate android --livereload --verbose
  4. You will see errors (on Windows 8.1)

If I do not perform part 3 above, I get this constantly looping: [cordova] Command finished with error code 1: C:\Users\Gary\AppData\Local\Android\Sdk\platform-tools\adb.exe -s,emulator-5584,shell,getprop,dev.bootcomplete [cordova] Running adb shell command “getprop dev.bootcomplete” on target emulator-5584… [cordova] Running command: C:\Users\Gary\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5584 shell getprop dev.bootcomplete

Output: Emulator shows: System UI isn’t responding X Close app, or Wait. Emulator shows: Application Error - The connection to the server was unsuccessful (http://192.168.103.129:8100) Upon clicking “OK”, screen turns white.

When I ctrl+c to stop the process, I get this error: ionic:cli-framework:utils:process error while killing process tree for 7700: { Error: Command failed: taskkill /pid 7700 /T /F ionic:cli-framework:utils:process ERROR: The process “7700” not found. ionic:cli-framework:utils:process ionic:cli-framework:utils:process at ChildProcess.exithandler (child_process.js:275:12) ionic:cli-framework:utils:process at emitTwo (events.js:126:13) ionic:cli-framework:utils:process at ChildProcess.emit (events.js:214:7) ionic:cli-framework:utils:process at maybeClose (internal/child_process.js:925:16) ionic:cli-framework:utils:process at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) ionic:cli-framework:utils:process killed: false, ionic:cli-framework:utils:process code: 128, ionic:cli-framework:utils:process signal: null, ionic:cli-framework:utils:process cmd: ‘taskkill /pid 7700 /T /F’ } +2s ionic:cli-framework:utils:process onBeforeExit handler: error from function: { Error: Command failed: taskkill /pid 7700 /T /F ionic:cli-framework:utils:process ERROR: The process “7700” not found. ionic:cli-framework:utils:process ionic:cli-framework:utils:process at ChildProcess.exithandler (child_process.js:275:12) ionic:cli-framework:utils:process at emitTwo (events.js:126:13) ionic:cli-framework:utils:process at ChildProcess.emit (events.js:214:7) ionic:cli-framework:utils:process at maybeClose (internal/child_process.js:925:16) ionic:cli-framework:utils:process at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) ionic:cli-framework:utils:process killed: false, ionic:cli-framework:utils:process code: 128, ionic:cli-framework:utils:process signal: null, ionic:cli-framework:utils:process cmd: ‘taskkill /pid 7700 /T /F’ } +12ms ionic:cli-framework:utils:process onBeforeExit handler: exiting (exit code 0) +11ms

My ionic info: ionic (Ionic CLI) : 4.3.1 (C:\Users\Gary\AppData\Roaming\npm\node_modules\ionic) Ionic Framework : @ionic/angular 4.0.0-beta.3 @angular-devkit/build-angular : 0.7.4 @angular-devkit/schematics : 0.7.4 @angular/cli : 6.1.4 @ionic/angular-toolkit : not installed

Cordova:

cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1) Cordova Platforms : android 7.1.4, browser 5.0.4 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.5, (and 3 other plugins)

System:

Android SDK Tools : 26.1.1 (C:/Users/Gary/AppData/Local/Android/sdk) NodeJS : v8.11.4 (C:\Program Files\nodejs\node.exe) npm : 6.4.1 OS : Windows 8.1

Other Information: I have tried updating adb.exe, & updating android studio. I have tried: ionic cordova platform rm android ionic cordova platform add android Updating to Nexus 6, API 28 (was using Pixel 2, API 23)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 20 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I could solve net::ERR_CLEARTEXT_NOT_PERMITTED problem with @adamduren https://github.com/ionic-team/ionic-cli/issues/3759#issuecomment-469881409 solution config.xml file, which created android:usesCleartextTraffic="true" option inside Androidmanifest.xml.

Have to note that the application didn’t compile with modified config.xml so I had to remove the modifications while keeping Androidmanifest.xml updated so the application compiled correctly. If I remove the option android:usesCleartextTraffic="true" from AndroidManifest.xml, the problem appears again.

Not sure if the problem is related, but after deep googling for net::ERR_CLEARTEXT_NOT_PERMITTED this is the only place where I found a solution.

Also had to add the following to my config.xml file to get past a net::ERR_CLEARTEXT_NOT_PERMITTED error popup.

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
    <application android:usesCleartextTraffic="true" />
</edit-config>

If you get error on build, add xmlns:android="http://schemas.android.com/apk/res/android" in widget tag of config.xml

As mentioned by @miqmago, just edit: yourapp…/platforms/android/app/src/main/AndroidManifest.xml and add the following tag:

<application … android:usesCleartextTraffic=“true” …>

Works fine here.

Thanks for clarifying!

Are you able to see your app on the 8100 port if you open your browser to the URL (or http://localhost:8100)? If so, it is likely unrelated to the port configuration and more of an issue with your device or emulator not being able to use your computer’s LAN IP. The device has to be on the same wifi network as the computer (which is not a concern with emulators).

You can also use livereload with port forwarding. Since it sounds like you’re using android, you can use adb reverse tcp:8100 tcp:8100 (adb docs) and then run ionic cordova run with --address=localhost (cli docs).

As for the 4200/8100 disparity: the Ionic CLI does not read angular.json. It assigns a port programmatically; i.e. it will use 8100, then 8101 if 8100 is in use. I believe hard-coding a port to use for an app is not supported, but it could be made into a feature request. Since we always pass --port to the Angular CLI, it probably doesn’t use the configured port in angular.json.

If you notice any disparity in configuring ng run app:serve vs ng run app:ionic-cordova-serve, it is likely an issue with the locally installed @ionic/angular-toolkit.