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:
- Download My Github repo: https://github.com/gchan82/heartstoneLibApp
- run npm install +/-3. launch android studio emulator (Nexus 6, API 28 or Pixel 2, API 23)
- run: ionic cordova emulate android --livereload --verbose
- 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
- fix(cordova): allow cleartext on localhost Starting with Android 9, cleartext support is disabled by default. We need to allow it again so livereload continues to work with `ionic cordova run android... — committed to ionic-team/starters by imhoffd 5 years ago
- fix(cordova): allow cleartext on localhost (#756) Starting with Android 9, cleartext support is disabled by default. We need to allow it again so livereload continues to work with `ionic cordova ru... — committed to ionic-team/starters by imhoffd 5 years ago
I could solve
net::ERR_CLEARTEXT_NOT_PERMITTEDproblem with @adamduren https://github.com/ionic-team/ionic-cli/issues/3759#issuecomment-469881409 solutionconfig.xmlfile, which createdandroid:usesCleartextTraffic="true"option insideAndroidmanifest.xml.Have to note that the application didn’t compile with modified
config.xmlso I had to remove the modifications while keepingAndroidmanifest.xmlupdated so the application compiled correctly. If I remove the optionandroid:usesCleartextTraffic="true"fromAndroidManifest.xml, the problem appears again.Not sure if the problem is related, but after deep googling for
net::ERR_CLEARTEXT_NOT_PERMITTEDthis is the only place where I found a solution.If you get error on build, add
xmlns:android="http://schemas.android.com/apk/res/android"in widget tag of config.xmlAs 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 runionic cordova runwith--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--portto the Angular CLI, it probably doesn’t use the configured port inangular.json.If you notice any disparity in configuring
ng run app:servevsng run app:ionic-cordova-serve, it is likely an issue with the locally installed@ionic/angular-toolkit.