5

I have a situation, I have pulled the latest changes from my branch and trying to run the application using tns run android command. The app is launched successfully but the API call is restricted throwing an error as soon as the app starts.

I have also gone through this answer but that's not the problem it seems. Because for other team members it is working fine. :/

    err {
JS:   "headers": {
JS:     "normalizedNames": {},
JS:     "lazyUpdate": null,
JS:     "headers": {}
JS:   },
JS:   "status": 0,
JS:   "statusText": "Unknown Error",
JS:   "url": null,
JS:   "ok": false,
JS:   "name": "HttpErrorResponse",
JS:   "message": "Http failure response for (unknown url): 0 Unknown Error",
JS:   "error": {
JS:     "originalStack": "Error: java.io.IOException: Cleartext HTTP traffic to elk.chennai-volunteer-294695.staging.c66.me not permitted\n    at new ZoneAwareError (file:///data/data/org.nativescript.chennaivolunteersapp/files/app/
tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:1298:33)\n    at onRequestComplete (file:///data/data/org.nativescript.chennaivolunteersapp/files/app/tns_modules/tns-core-modules/http/http-request/http-request.js:
45:34)\n    at Object.onComplete (file:///data/data/org.nativescript.chennaivolunteersapp/files/app/tns_modules/tns-core-modules/http/http-request/http-request.js:37:13)",
JS:     "zoneAwareStack": "Error: java.io.IOException: Cleartext HTTP traffic to elk.chennai-volunteer-294...
Yashwardhan Pauranik
  • 5,370
  • 5
  • 42
  • 65

2 Answers2

10

Starting with Android 9.0 (API level 28), cleartext support is disabled by default.

Update your manifest file with the android:usesCleartextTraffic flag.

<application ... android:usesCleartextTraffic="true" ...>
Manoj
  • 21,753
  • 3
  • 20
  • 41
  • Sorry it didn't work for you. You must give enough details if you think something is not working. There is nothing changed so far, if http connection was issue adding this flag should resolve it. – Manoj Oct 03 '20 at 22:54
  • https://play.nativescript.org/?template=play-ng&id=encw3e you can check this demo. I created same offline but even after adding android:usesCleartextTraffic="true" on local files, it still not working... – Himanshu Bansal Oct 04 '20 at 09:40
  • You can not edit manifest file with Playground, if you have issues please share a sample project on Git. – Manoj Oct 04 '20 at 18:21
  • https://github.com/Skillnter/nativescript-test-file-issue Please check and do let me know – Himanshu Bansal Oct 04 '20 at 19:47
  • There were angular compiler issues in your sample, but after resolving them it worked just fine, I didn't find any issues while uploading. – Manoj Oct 05 '20 at 04:08
6

Go to: your-project\App_Resources\Android\src\main\AndroidManifest.xml

Update your manifest by adding android:usesCleartextTraffic="true" to existing rules in <application></application> tag, like as seen bellow

<application
    ...
    ...
    android:usesCleartextTraffic="true"
    ...
    ...
</application>
Harrison O
  • 1,119
  • 15
  • 20