title: NativeScript Angular Cleartext HTTP traffic to localhost not permitted
body: <p>I am working with angular version of native script and trying to create a login system to my network.<br>
  Below is my code that attempts to log into the network.</p>
  
  <p>home.component.ts</p>
  
  <pre><code> import { LoginService } from '../Services/login/login.service';
   export class LoginComponent implements OnInit {
  
   public user: User;
   loginForm: FormGroup;
  
   constructor(private router: Router,
       private userService: UserService,
       private page: Page,
       public  loginDetails: LoginDetails,
       private LoginService: LoginService
  
   ) {
  
       this.user = new User();
       this.user.email = "m@m.com";
       this.user.password = "pass123";
       this.user.logo = "~/Images/opos_logo.png";
   }
  
   submit() {
  
      /* set a user variable with data from the formGroup */
      const user: string = this.user.email;
      /* set a password variable with data from the formGroup */
      const password: string = this.user.password;
  
      this.LoginService.loginUser(user, password)
          .subscribe(data =&gt; this.checkUser(data));
   }
  }
  </code></pre>
  
  <p>Services/login/login.service.ts</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { HttpClient } from '@angular/common/http';
  import { Component, OnInit } from "@angular/core";
  import { Jwt } from '../../Classes/jwt';
  
  
  @Injectable({
      providedIn: 'root'
  })
  export class LoginService {
  
  
    loginUrl = 'http://localhost/Login.w';
  
    constructor(private _http: HttpClient) { }
  
    loginUser(user, pass) {
        return this._http.get&lt;Jwt&gt;(
            this.loginUrl, { params: { fi_user: user, fi_pass: pass } });
    }
  }
  </code></pre>
  
  <p>When I tried to run my app like this I would get the following error: </p>
  
  <p>"originalStack": "Error: java.io.IOException: Cleartext HTTP traffic to localhost not permitted\n at new ZoneAwareError        (file:///data/data/org.nativescript.preview/files/app/tns_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:1298:31)\n at onRequestComplete     (file:///data/data/org.nativescript.preview/files/app/tns_modules/@nativescript/core/http/http-request/http-request.js:54:30)\n at Object.onComplete (file:///data/data/org.nativescript.preview/files/app/tns_modules/@nativescript/core/http/http-request/http-request.js:43:7)" </p>
  
  <p>To tried to fix the issue by following the suggestions on the post <a href="https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted/50834600">Android 8: Cleartext HTTP traffic not permitted</a> and followed the advice on that post. 
  I added a androidmanifest.xml file to my program (this was not already part of the application as such I am not sure if the application is accessing the file) on the path /App_Resources/Android/AndroidManifest.xml. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="__PACKAGE__"
  android:versionCode="1"
  android:versionName="1.0"&gt;
  
  &lt;supports-screens
      android:smallScreens="true"
      android:normalScreens="true"
      android:largeScreens="true"
      android:xlargeScreens="true"/&gt;
  
  &lt;uses-sdk
      android:minSdkVersion="17"
      android:targetSdkVersion="__APILEVEL__"/&gt;
  
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  
  &lt;application
      android:name="com.tns.NativeScriptApplication"
      android:allowBackup="true"
      android:icon="@drawable/icon"
      android:label="@string/app_name"
      android:theme="@style/AppTheme"
      android:networkSecurityConfig="@xml/network_security_config"&gt;
  
      &lt;activity
          android:name="com.tns.NativeScriptActivity"
          android:label="@string/title_activity_kimera"
          android:configChanges="keyboardHidden|orientation|screenSize"
          android:theme="@style/LaunchScreenTheme"&gt;
  
          &lt;meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" /&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name="com.tns.ErrorReportActivity"/&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>I also added a network_security_config.xml file which the Stack overflow post was suggesting to the path res/xml/network_security_config.xml   </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;network-security-config&gt;
     &lt;domain-config cleartextTrafficPermitted="true"&gt;
        &lt;domain includeSubdomains="true"&gt;domain.com (to be adjusted)&lt;/domain&gt;
     &lt;/domain-config&gt;
  &lt;/network-security-config&gt;
  </code></pre>
  
  <p>I also tried to add the application android:usesCleartextTraffic="true" tag to my home.component.html to fix the error but this did not resolve the issue.  </p>